Salesforce Platform Developer I Certification Guide
上QQ阅读APP看书,第一时间看更新

Approval processes

If you require a chain of steps that need to be followed in order to get a specific record approved, then approvals can take this automation a step further. Businesses sometimes need some departments or people to review the data of a specific record for compliance reasons.

For example, you let sales representatives create and negotiate opportunities with products and customer negotiated prices and/or discounts, but you want a sales manager to first review and approve the final prizes before a quote gets sent out to the customer. Or you could have an internal process for employees to submit holidays, leave requests, or expense notes, and have them first approved by their line manager before those are assigned to HR for further treatment.

In an approval process, you can specify each step that needs to be taken to get an approval, including who can request an approval, who needs to approve at each step, and what needs to happen in Salesforce at each point of the process.

The following are the steps to create an approval process:

  1. Specify the entry criteria.
  2. Specify the approver and editable record properties while the record is within the approval process.
  3. Select email notification templates (notify the approver, and notify the submitter of approval or rejection).
  4. Select which fields of the record to display on the approval page layout for easy review by the approver.
  5. Specifying the initial submitters (which users are allowed to submit a record for approval).

Once the approval process has been created, you can do the following:

  • Specify an initial submission action: What needs to happen when a record is submitted for approval, such as locking the record so it can no longer be edited while within the approval process
  • Specify one or more approval steps
  • Specify final approval actions; for example, unlocking the record and updating a field to Approved
  • Specify final rejection action; for example, unlocking the record and updating a field to Rejected
  • Specify a recall action: What needs to happen if a user recalls his approval request, such as unlocking the record and updating a status back to the previous value

You can make use of the same actions to perform, such as in workflow rules:

  • Creating a task
  • Sending an email alert
  • Performing field updates to the record itself or its parent in a master-detail relationship
  • Sending an outbound message to external systems
  • In addition to those, you have an extra action to lock or unlock the record for editing:

But, actions can only be executed immediately. Hence, no time-dependent actions are possible within an approval process. Of course, with what you have already learned, you can find some workarounds, right? These include creating a hidden checkbox or other field type and having your approval flow update that checkbox, and then having a workflow rule kick off of this field update, performing a time-dependent action. But that's not what we are going to show you in this course. Just keep in mind that you can creatively work around some limitations of the tools provided by the platform.

Let me give you a high-level example of a possible approval process—when sales representatives put an opportunity in the stage proposal/quote, management wants to check whether what was proposed adheres to company pricing rules. The approval needs to automatically assign the opportunity for approval to the correct user in your org based on the amount of the opportunity.

If the amount of the opportunity is 0, then users should not be permitted to submit the opportunity for approval, as this would cause a major overload of approval requests. The opportunity record should be locked for editing while it's pending approval. The criteria for assigning the correct approver are as follows: if the amount is less than 50,000, the request may automatically be approved; if the amount is less than or equal to 500,000, an approval is required by the direct manager of the submitter.

Finally, if the amount is greater than 500,000, secondary approval is needed by the VP of Sales. If all requests are approved, the status of the opportunity can be updated to Approved and the record should be unlocked. If any requests are rejected, the status needs to be changed to Rejected and the record needs to be unlocked. Of course, approvers need to be notified by email that they have a record to approve and the submitters need to be notified upon approval or rejection of their submission.

This is a typical example of a business process that you would use an approval process for.

For the approval process, the requirements are as follows:

  1. First, we'll need a new field called Status on our Review object with values of Pending Review, Approved, and Declined, and we'll set Pending Review as the default value.
  2. When a Review has the status Pending Review, or the status is changed to Pending Review, the Review needs to be approved by a specific user (you!).
  3. When it gets approved, the status should be updated to Approved, or, if it gets declined, the status should be updated to Declined.
  4. We'll also update our roll-up summary fields on the movie record, to not include Review records that are not (yet) approved in the Nbr of Ratings and Total Rating fields.