- Salesforce Platform Developer I Certification Guide
- Jan Vandevelde Gunther Roskams
- 1292字
- 2021-08-20 10:02:23
Creating the approval process
Now, let's create an approval process using our BIM DB app:
- Navigate to Setup | Object Manager, select the Review object, and click Fields & Relationships. Click the New button to create a new custom field.
- Choose Picklist as the type, and set the label name to Status. For values, select the second radio button, Enter values, with each value separated by a new line, and, in the big editor box, enter the following values each on a new line (don't use commas or anything to separate the values; just hit enter to go to the next line):
- Pending Review
- Approved
- Declined
- Also, select the Use first value as default value checkbox and mark the field as Required. Hit Next and Save, leaving all the defaults for the page layouts and field level security:
Now that we have the field created, we also have some review records in our database present. Let's assume that they are all correct and can be published. We could update all those records with the Data Loader and set the Status field to Approved, or, because we just created this Status field and they are all blank, and we can assume that all current review records are correct and can be approved (because we created them ourselves), we can also use the picklist value replacement tool on this field itself.
- So from Setup | Object Manager on our Review object in Fields & Relationships, click the dropdown on the right-hand side of our Status field and select Replace:
This is a little menu only available for picklist fields that lets you replace old value or blank fields with a new value.
- You could write a value in Exact Value Changing From, but, in our case, there is no value. Since it's the blank values that we now want to populate with Approved, select the Replace all blank values checkbox and set Select Value Changing To Approved and click Replace:
- Depending on the number of records in your database that need to be updated, you'll be presented with a confirmation message, as shown in the following screenshot:
- Wait until you receive the following email confirmation that the job has been successfully executed:
- If you now navigate to our BIM DB app, open up The Godfather, and then open up one of its reviews through the related list and you'll see that our new Status field is there and filled in with Approved, as follows:
- Before we can start on our approval process, we'll need to create an email template for use within our approval process. So, navigate to Setup and choose Classic Email Templates from the sidebar, under the Email category:
- Click New Template and choose Text (we are not going to bother creating an HTML template for this exercise; otherwise, we would also need to create an HTML header first, and that's not what this course is about).
- Folder: Unfiled Public Classic Email Templates
- Available for Use: Checked
- Email Template Name: Review Approval Notification
- Template Unique Name: Review_Approval_Notification
- Subject: A Review has been sent for approval
- Body:
Dear {!ApprovalRequest.Process_Approver},
{!Approval_Requesting_User.Name} has submitted a new Review: {!Review__c.Name} for approval.
Please verify this review and approve or reject it by navigating to: {!ApprovalRequest.Internal_URL}
- Only approved reviews will be published and count toward a movie's rating:
- Now that we have an email template to use, let's continue with creating our approval process.
- Navigate back to Setup and, in the setup search bar, type Approval to find the Approval Processes menu, which is located under the Process Automation category and click it:
- Select the Review object in the Manage Approval Processes For picklist, which will show you all currently active and inactive approval processes that exist in your org for the Review object. Currently, there should be none. Click the Create New Approval Process button and use the standard setup wizard:
- Set Default approval for reviews as the name and hit Next:
- For the Entry Criteria, set it to Review: Status - equals - Pending Review, and hit Next:
- On the approver selection page, set the Next Automated Approver Determined By field to Manager, and also select the second radio button, so that administrators and the current approver may edit the record while it is in the approval process, and hit Next:
- Select our newly created email template called Review Approval Notification and hit Next:
- On the next page, you can select a number of fields that you want to show on the approval page so that an approver can have a quick glimpse of what the contents of the record are without having to navigate to the record itself. Select Review Nbr, Movie Title, Description, Rating, and Created By. Also, check the checkbox to show approval history information on the approval page and the Allow approvers to access the approval page from within the Salesforce application, or externally from a wireless-enabled mobile device option, and hit Next:
- Select the people who can submit a review record for approval. I've selected the Movie Owner and the Record Creator of the review itself. I've also enabled the Allow submitters to recall approval requests and hit Save:
- The wizard will ask you whether you want to add a first approval step, or whether you would like to do this later and already save your approval process. Choose to add the first step. As our flow will only contain one step, give it the name, New Review. It will have defaulted to Step Number 1. Hit Next:
- Select All records should enter this step and hit Next:
- Now, you can select who will need to approve the record. Select a fixed approver (third option) and select yourself as User. Leave the Approve or reject based on FIRST response, as we won't have multiple steps, and also select The approver's delegate may also approve this request checkbox. This allows an approver to select a backup user on his user record to approve on his behalf while on holiday or in case of illness. Hit Save:
- Now, the wizard will ask you whether you would like to define an approval action for this step, a rejection action, or just save your process and create the actions later. Let's choose to create an approval action already and select Field Update and click Go!:
- In the name of the Field Update action, fill in Update Review To Approved, select Status as a field to update, and choose Approved to set it to a specific value, and then hit Save:
- You'll now find yourself on the approval overview page. Find the Approval Steps section and click the Show Actions link on the left of step 1:
- You'll see the Field Update action in the Approval Actions section you just created, but we don't have Rejection Actions for our step yet. So, click Add New in the Rejection Actions section and select Field Update:
- Now, set the name to Update review to declined, select the Status field as the field to update, and set the value to Declined, and then hit Save:
- Now, you'll be back on the approval overview page and you have defined an approval action and also a rejection action. Our approval process is done, but we still need to activate it.