Sub topic 8
Approval processes for sign-off steps
This chapter assumes you can build objects and fields in the Object Manager, write a simple formula, and read a short Apex snippet. It also assumes you know the basics of record-triggered flows from the earlier chapters.
An approval process is a declarative feature that routes a record to one or more people for a yes or no decision. It records who decided, when, and with what comments. Use it when the requirement is a sign-off, such as a discount above 20 percent, a large expense, or a contract exception.
The working model
An approval process belongs to one object. It has five parts:
- Entry criteria decide whether a record can be submitted. Example:
Amount > 50000 AND StageName = 'Negotiation'. - Approval steps run in order. Each step names its approvers and says what happens when the step is approved or rejected.
- Approver sources can be specific users, a queue, a public group, the submitter's manager, or a user field on the record.
- Actions run at set points: initial submission, each step, final approval, final rejection, and recall. The action types are field update, email alert, task, and outbound message.
- Record locking keeps the record from being edited while it waits for a decision.
Steps and approvers
Each step can have its own entry criteria. A record that fails a step's criteria can skip the step, be approved automatically, or be rejected. This lets one process handle several levels. For example, the manager approves every discount, and finance approves only discounts above 30 percent.
When a step has several approvers, you choose one of two rules:
- Unanimous: every approver must approve. One rejection rejects the record.
- First response: the first approver to act decides the outcome for everyone.
A queue works well when any member of a team may act, such as a finance desk. Combine it with first response so that one person from the queue can decide. Approvers can also set a delegated approver on their user record, so requests are not stuck while they are away.
Record locking
When a record is submitted, it locks. Regular users cannot edit it. You choose in the process settings whether only administrators, or administrators and the current approvers, can edit it during approval.
Locking is the feature that makes approval processes reliable for sign-off. It stops a submitter from changing the amount after the manager has looked at it. It also causes the most surprises. A user sees "record is locked" and assumes something is broken. A flow that tries to update a locked record as a user without permission to edit it can fail. If your design has other automation updating records that are in approval, test that case directly.
Actions and how they fit with other automation
Use the actions to make the status visible and to drive the next step:
- Initial submission: set
Status__c = 'Pending'. - Final approval: set
Status__c = 'Approved'and send an email alert to the submitter. - Final rejection: set
Status__c = 'Rejected'and create a follow-up task. - Recall: reset the status to
Draft.
A field update from an approval action is a normal save. Triggers and record-triggered flows on that object can run again. A flow that fires on Status__c changing to Approved is therefore a common and supported way to continue the work, for example to create an order after sign-off. Keep the approval process responsible for the decision, and keep the follow-up work in a flow or Apex.
Submitting from a flow or Apex
Users submit with the Submit for Approval button. Automation can submit as well. In Flow, use the Submit for Approval action. In Apex, use Approval.ProcessSubmitRequest:
public class DiscountApprovalService {
public static Approval.ProcessResult submit(Id opportunityId) {
Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();
req.setObjectId(opportunityId);
req.setComments('Submitted automatically for discount approval.');
req.setProcessDefinitionNameOrId('Discount_Approval');
req.setSkipEntryCriteria(false);
return Approval.process(req);
}
}Discount_Approval is the API name of the process. It must exist and be active, and the record must meet its entry criteria. Otherwise the call throws an exception. For several records, build a list of requests and pass the list to Approval.process. This keeps the code bulk safe and uses fewer DML-related limits than one call per record.
When to choose an approval process
| Requirement | Better fit |
|---|---|
| One manager or queue approves a record, then the record moves on | Approval process |
| Audit trail of approver, time and comments on the record | Approval process |
| Several steps that cross different users, with work between approvals | Flow Orchestrator |
| Approver needs to fill in extra fields or see a custom screen | Screen flow, or Orchestrator with screen steps |
| Condition on a single record that needs no human decision | Record-triggered flow or validation rule |
An approval process is the simplest tool for a plain sign-off. It becomes awkward when the "approval" is really a multi-stage business process with tasks in between. That is the point to look at Flow Orchestrator, which is covered in a later chapter.
Common errors
- Entry criteria too narrow. Users click Submit and get an error that the record does not meet the criteria. Test with real records at the edge of your conditions.
- No approver found. A manager-based step fails if the submitter has no manager set. Add a fallback approver in the step settings.
- Multiple active processes on one object. Salesforce checks them in order, and the first process whose criteria match is used. Put the most specific process first, and make sure the criteria do not overlap in surprising ways.
- Editing an active process. You cannot change an active process in place. Deactivate it first, and be aware that records already pending are tied to the version they started under. Plan changes for a quiet period, or clone the process.
- Tests that ignore locking. Apex tests that update a record after submitting it can fail on the lock. Test the full submit, approve and reject path.
Exercise
A sales rep submits an opportunity for discount approval. The manager approves it, and the opportunity must then create an order record. Which tool owns the approval, which tool creates the order, and how does the second one know to run?
Show answer
The approval process owns the sign-off. A final approval action sets a field such as Status_c to Approved. A record-triggered flow on Opportunity, fired when Status_c changes to Approved, creates the order. This keeps the decision and the follow-up work in separate, testable pieces.
Exercise
An approval step lists a finance queue as approver. Any one finance user should be able to decide, and one decision should be enough. Which setting do you choose, and what happens if you pick unanimous instead?
Show answer
Choose first response. With unanimous, every approver must approve, and with a queue that can leave the step waiting on people who never act, so the request stalls.