Sub topic 2
The building blocks of an approval process
This chapter assumes you can navigate Setup, you know how objects, fields, and records relate, and you understand users, roles, and queues. You should also know how validation rules and formulas work. Later chapters cover each block in detail. This chapter shows how the blocks fit together, so you can read an approval process definition and predict what it will do.
The process definition
An approval process is a metadata definition attached to one object. It describes which records can enter the process, who must review them, and what happens at each stage. A record moves through the process as a single approval instance. Each submission creates a new instance, and the definition itself never changes while a record moves through it.
You create a process in Setup under Approval Processes. You pick the object first, then choose between two wizards:
- The Standard Setup Wizard exposes every option. Use it for anything non-trivial.
- The Jump Start Wizard fills in defaults and limits your choices. It is useful for a quick prototype.
An object can have several approval processes. Only one can be active for a given record at a time, so the processes need entry criteria that do not overlap, or an order in which they are evaluated.
The parts at a glance
A process has these building blocks:
| Block | Question it answers | Where it applies |
|---|---|---|
| Entry criteria | Which records may enter? | Once, at submission |
| Initial submitters | Who may submit? | Once, at submission |
| Approval steps | In what order is the record reviewed? | Each step in sequence |
| Step criteria | Does this step apply to this record? | At the start of each step |
| Approvers | Who must respond? | Each step |
| Approval actions | What happens automatically? | Submission, approval, rejection, recall |
| Record locking | Who can edit during review? | From submission to final outcome |
The diagram below shows how a record travels through these blocks.
Entry criteria and initial submitters
Entry criteria decide whether a record may enter the process. You write them in one of two ways:
- Criteria-based: choose field conditions, such as
Amountgreater than 10000 andStagenot equal toClosed Lost. - Formula-based: write a Boolean formula, for example
AND(Amount > 10000, NOT(ISBLANK(Discount__c))).
If a user submits a record that fails the criteria, Salesforce refuses the submission with an error. If you leave the criteria empty, every record of that object is eligible.
Entry criteria are checked only at submission. If the data changes later, the record stays in the process. A record that was eligible when submitted can become ineligible while pending, and the process does not notice.
Initial submitters are the users allowed to submit. You can choose the record owner, the owner's role and subordinates, specific roles, groups, or users. If you leave the list at its default, only the owner and administrators can submit. A common mistake is testing as an administrator, where submission always works, and then finding that sales users do not see the Submit for Approval button.
Approval steps and step criteria
A process contains one or more steps, and they run in order. Each step has a name, a step number, and three decisions to make.
- Which records does the step apply to? You can let all records enter, or apply step criteria. Step criteria use the same filter or formula options as entry criteria.
- Who approves? See the next section.
- What if the criteria are not met? For the first step, you choose between approving the record automatically, rejecting it, or, with the second option on a later step, skipping to the next step. For the first step you can also choose to go straight to final approval.
This lets you build tiered approval. For example, step 1 applies to all discounts and goes to the sales manager. Step 2 applies only when the discount is over 20 percent and goes to the finance director. A record with a 10 percent discount skips step 2 and is approved once the manager responds.
Each step also has a setting for what happens when an approver rejects: reject the request outright (the final rejection actions run), or send the record back to the previous approver. Choose carefully, because the first option ends the process.
Choosing approvers
For each step you assign approvers from these sources:
- A specific user, or the manager of the submitter. The manager comes from the standard Manager field on the user record. If that field is empty, the step has no approver and the submission fails.
- A queue. Any queue member can respond. Queues must support the object being approved.
- A related user. A user lookup field on the record, such as
Account Manager__c. This allows approvers to change per record. - A hierarchy field. Salesforce follows a user hierarchy field up the chain.
- A delegated approver. On each user record, you can set a delegate who may respond on the user's behalf. A delegate does not replace the approver. Both can respond.
When a step names more than one approver, you choose between two rules:
- Unanimous: every approver must approve. One rejection ends the step as rejected.
- First response: the first approver to respond decides the outcome, and the other requests are removed.
Queues behave like first response. Anyone in the queue can claim the request and respond, and the others no longer need to act.
Approval actions
Actions run automatically at defined points. There are five points where you can attach them:
| Action point | When it runs |
|---|---|
| Initial submission | When the record is submitted |
| Step approval | When one particular step is approved (optional, per step) |
| Step rejection | When one particular step is rejected (optional, per step) |
| Final approval | When the last step is approved |
| Final rejection | When the request is rejected at any step that rejects outright |
| Recall | When the submitter or an administrator withdraws the request |
Each point can hold any mix of four action types: a field update, an email alert, a task, and an outbound message. Typical uses are setting Status__c to Pending on submission, Approved on final approval, and Rejected on final rejection, and emailing the submitter with the result.
Two practical points apply. Field updates in approval actions can change a locked record, because the system performs them. Also, the initial submission actions include a default record lock, and you must keep that lock enabled if you want it.
Record locking
By default a record is locked as soon as it is submitted. While it is locked, users cannot edit it, except for the following:
- Administrators can always edit.
- Approvers can edit the record if you choose Administrators or the currently assigned approver can edit locked records in the process settings.
The record stays locked until it is finally approved, finally rejected, or recalled. Then it unlocks automatically. Locking applies to the record you submitted. Child records, such as the line items on an opportunity, remain editable in many cases, so do not assume the whole record tree is frozen.
You can also lock or unlock a record yourself. An administrator can unlock a pending record through the Unlock Record option in Setup tools, and Apex can call Approval.lock() and Approval.unlock().
Activation and versioning
A process is built inactive. You can only edit it while it is inactive, and you can only activate it once it has at least one step. Salesforce does not let you edit an active process, so to change one you clone it as a new version. Records already pending keep using the version they started with. Newly submitted records use the active version.
For this reason, give each process a clear developer name, because Apex and the API refer to it by that name. A name like Discount_Approval is easier to maintain than a generated one.
Putting it together
Suppose you build Discount Approval on Opportunity:
- Entry criteria:
Discount_Percent__c > 0andStageNameis notClosed Lost. - Initial submitters: the opportunity owner.
- Step 1: all records, approver is the submitter's manager, rejection ends the process.
- Step 2: only when
Discount_Percent__c > 20, approver is theFinance Approversqueue, first response. - Initial submission actions: lock the record, set
Approval_Status__ctoPending. - Final approval action: set
Approval_Status__ctoApproved. - Final rejection and recall actions: set
Approval_Status__ctoRejectedorRecalled.
Reading this list, you can predict that a 10 percent discount needs one approval, a 25 percent discount needs two, and a zero discount cannot be submitted.
Exercise
An opportunity enters an approval process with Amount of 15000, and entry criteria require Amount > 10000. While the request is pending, the owner is blocked from editing, but an administrator reduces the amount to 5000. What happens to the approval request, and why?
Show answer
The request stays in the process and continues normally. Entry criteria are evaluated only at submission, so a later change to the data does not remove the record from the approval. The step criteria of steps that have not yet started are evaluated when each step begins, so they could use the new value.
Exercise
A step is assigned to a queue with three members, and a first response rule applies. Two members approve at nearly the same time. How many approvals does the step need, and what does the other member see?
Show answer
The step needs one approval. The first response decides the outcome, and the remaining work items are removed, so the other member no longer has a request waiting for them.