Sub topic 5
Choosing approvers
This chapter assumes you can build a basic approval process in Setup and know the difference between users, queues, and lookup fields. The Apex examples assume basic Apex and SOQL.
An approval step defines when a record qualifies and who must decide on it. The approver choice sets who receives the request, who can act on it, and what happens when the process can't find anyone. This chapter covers the options, how each resolves at run time, and the failure modes.
The approver options in a step
When you add a step, you pick one of two broad strategies.
- Automatically assign approvers. The process works out the approvers from the step definition when the request reaches that step.
- Let the submitter choose manually. A person picks the approver. For the first step, the submitter picks when submitting. For later steps, the previous approver picks when responding.
Automatic assignment gives you these approver types, which you can mix in one step:
| Type | Resolves to | Typical use |
|---|---|---|
| User | A specific named user | A fixed reviewer such as a finance controller |
| Queue | Any member of a queue | A team that shares the workload |
| Related user | A user found through the record | The record owner's manager, or a user lookup field on the record |
You can also assign the next approver from the user hierarchy. That is the Manager field on the user record, which this chapter covers below.
Fixed users
Choose a fixed user when one person always owns the decision. It is the simplest option and the easiest to audit. The weakness is maintenance. If that person leaves or changes roles, you must edit the process. Deactivating the user does not reroute pending requests for you. For anything that depends on a team, prefer a queue.
Queues
A queue is a good fit when several people can make the same decision. Keep these points in mind:
- The queue must list the object as a supported object. Otherwise you can't select it for that process.
- The request goes to the queue, and any member can open and act on it. Members get notified according to the queue's email settings.
- Queue membership is managed outside the process. Adding a person to the queue gives them approval rights immediately, with no change to the process.
- When a member acts, the history records that individual as the actor, not the queue.
Queues also interact with the rule for multiple approvers. That rule applies when several users or related users are listed in one step, and the next chapter covers it.
Related users
A related user is chosen from the record at the time of submission, so one process can serve many different approvers. You can pick from:
- A standard user relationship on the record, such as the record owner or the user who created it.
- A custom lookup field to User on the record, for example
Regional_Director__c. - The manager of one of those users, using the Manager field on the user record.
Custom lookup fields are the most flexible choice. If you add a Technical_Reviewer__c lookup to the record, the sales rep, a flow, or an integration can fill it, and the approval follows the value.
Manager hierarchy
In the process definition you can have the next approver determined by the user hierarchy, using the standard Manager field. You can choose whose manager is used, such as the submitter's or the record owner's. This works well for escalation across several steps: each step moves one level up the management chain.
The chain depends on clean data. A user with a blank Manager field leaves the process with nobody to route to. Check the Manager field for all likely submitters before you rely on this option.
When the related field is blank
If a related user field is empty when the process needs it, the process can't assign anyone. Submission fails with an error such as "Process failed. First step has no valid approvers." The record isn't submitted and isn't locked. You can prevent this in two ways:
- Add entry criteria that require the field to be filled, for example
NOT(ISBLANK(Regional_Director__c)). - Add a validation rule that makes the lookup required once the record reaches the relevant stage.
Entry criteria are the better choice when the field being blank is a legitimate state for some records. In that case the record simply doesn't qualify, and the user doesn't hit an error.
Manual selection
Manual selection fits cases where the right approver is a judgment call, such as choosing a subject-matter expert. It trades consistency for flexibility. Two downsides:
- The submitter can choose anyone who can act as an approver, so the process can't enforce who gets picked.
- Automation that submits records, such as Apex or a flow, has to supply the approver itself.
From Apex, pass the chosen users with setNextApproverIds:
Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();
req.setComments('Please review the discount.');
req.setObjectId(opportunityId);
// Required when the first step uses manual selection.
req.setNextApproverIds(new List<Id>{ reviewerUserId });
Approval.ProcessResult result = Approval.process(req);
System.debug('Submitted: ' + result.isSuccess());If the first step is automatic, Salesforce ignores any approver Ids you pass. If it is manual and you leave them out, the submission fails.
Delegated approvers
Each user record has a Delegated Approver field. It names someone who can respond to approval requests on that user's behalf, which is useful during leave or travel. The approval process must allow delegation. Where the step offers it, enable the option so requests can be acted on by the delegate.
The delegate can approve or reject, but the request was still assigned to the original approver. Salesforce keeps both facts. In ProcessInstanceWorkitem, OriginalActorId holds who the request was first assigned to, and ActorId holds who it is currently assigned to. To see who actually responded, read the actor on ProcessInstanceStep.
List<ProcessInstanceWorkitem> items = [
SELECT Id, OriginalActor.Name, Actor.Name
FROM ProcessInstanceWorkitem
WHERE ProcessInstance.TargetObjectId = :opportunityId
AND ProcessInstance.Status = 'Pending'
];
for (ProcessInstanceWorkitem w : items) {
System.debug('Assigned to ' + w.OriginalActor.Name + ', currently ' + w.Actor.Name);
}Delegation is per user, not per process. Setting a delegate changes who can act on every approval request assigned to that user, not only one process. Review it when someone's absence ends, because the delegate keeps access until the field is cleared.
Choosing between the options
| Situation | Best choice | Reason |
|---|---|---|
| One person always decides | User | Simple, but needs an edit if they leave |
| A team shares the work | Queue | Membership changes without touching the process |
| Approver depends on the record | Related user lookup | One process, many approvers |
| Escalation up the management chain | Manager hierarchy | Each step goes one level higher |
| The right person varies case by case | Manual selection | Flexible, but not enforced |
| Approver is often away | Delegated approver on the user | Requests keep moving |
Common problems
- "No valid approvers" on submit. A related user field or the Manager field is blank. Fill it, or add entry criteria.
- A queue can't be selected. The queue doesn't support the object. Add the object to the queue in Setup.
- The wrong person gets requests. A lookup field was changed after submission. Approvers are resolved when the step starts, so a later change doesn't affect a request that is already pending. A recall and resubmit picks up the new value.
- A deactivated user holds a pending request. The request stays assigned to them. Reassign it through the work item, or recall and resubmit.
- Apex submission fails for a manual step.
setNextApproverIdswas not set.
Exercise
A process uses a custom lookup field, RegionalDirector_c, as the related user for its first step. A sales rep submits an opportunity where that field is empty. What happens, and how would you prevent it without showing users an error?
Show answer
Submission fails because the step has no valid approver, and the record is not locked or submitted. To prevent it, add entry criteria such as NOT(ISBLANK(RegionalDirector_c)) so records without a director never qualify for the process. A validation rule that requires the field would also work, but it blocks saving instead of simply skipping the process.
Exercise
A manager named Priya is on leave, and her Delegated Approver is set to Sam. A request was assigned to Priya. Which field on ProcessInstanceWorkitem shows Priya, and where would you look to confirm that Sam actually responded?
Show answer
OriginalActorId (or OriginalActor.Name) shows Priya, the original assignee. To confirm who responded, query the Actor on the related ProcessInstanceStep records, which records the user who took the action.