Sub topic 7
Actions on submission, approval, rejection, and recall
This chapter assumes you know how to build an approval process shell, with entry criteria, steps, and approvers, and that you can create a field update in Setup. The Apex sections assume basic Apex and SOQL. Earlier chapters covered how a record enters a process and who approves it. Here you decide what the process does automatically when the request changes state.
Why actions matter
A process with entry criteria and approvers decides who answers. It does not, by itself, tell anyone else what happened. If the process does not update a status field, notify the requester, or unlock the record, users have to track the outcome by hand. Actions close that gap.
An action is an automated task the process runs when the request reaches a particular point. Salesforce groups actions into four sets, plus optional step-level actions.
The four action sets
| Action set | Runs when | Default lock behavior |
|---|---|---|
| Initial submission actions | A user (or Apex) submits the record | Record is locked |
| Final approval actions | Every required step has approved | Record stays locked |
| Final rejection actions | The request is rejected and the process ends | Record is unlocked |
| Recall actions | The submitter or an administrator withdraws a pending request | Record is unlocked |
Locking is the topic of the next chapter. For now, note that the lock or unlock is part of the action set, so you choose it when you configure the set. You can change the final approval lock setting if you want the record editable afterward.
Each set can contain four action types: field update, email alert, task, and outbound message. The chapter after next covers those types in detail. This chapter is about when each set fires and how to choose what goes in it.
Initial submission actions
These run once, at the moment of submission, before any approver acts. Typical uses:
- Set a status field such as
Approval_Status__c = 'Submitted'. - Record the submission date in a custom field.
- Email the approver or a team. Approvers also get their own approval request notification, so use this for other stakeholders.
Every approval process has a record lock on submission, and you cannot turn that off. That is why the status field update matters. Users who open a locked record need a visible reason it cannot be edited.
Final approval actions
These run only after the last step approves. If your process has three steps, the final approval actions do not run when step one approves. They run after step three.
Typical uses:
- Set
Approval_Status__c = 'Approved'. - Stamp an approved-date field.
- Email the record owner.
- Create a follow-up task, such as "Send contract to customer."
Approval actions also run on records that are locked. The process runs them as the system, so a locked record can still receive the field updates you configured.
Final rejection actions
These run when the request is rejected and the process ends. Whether a rejection ends the process depends on the step's rejection behavior, which you set per step:
- Perform all rejection actions for this approval process. The request ends. Final rejection actions run.
- Go back to the previous approver. The request returns to the previous step's approvers. The final rejection actions do not run. (This choice is not available on the first step.)
This is a common source of confusion. If your "Rejected" status never appears, check whether the rejecting step sends the request back instead of ending it.
Typical final rejection actions:
- Set
Approval_Status__c = 'Rejected'. - Email the submitter, and ideally include the approver's comments.
- Create a task for the owner to revise the record.
The default unlocks the record so the owner can edit and resubmit.
Recall actions
A recall withdraws a pending request. It is not a rejection and not an approval, so neither of those sets runs. Only recall actions run.
Two conditions apply:
- The process must have Allow submitters to recall approval requests enabled. If it is off, only an administrator can recall.
- Recall applies to a pending request. You cannot recall one that has already been approved or rejected.
Typical recall actions: reset the status field to Draft (or Recalled) and unlock the record. If you forget the status reset, the field keeps saying Submitted after the request is gone.
Step-level actions
Besides the four process-wide sets, each approval step has its own approval and rejection actions. Step-level approval actions run when that one step is approved. Use them for events tied to one stage, for example notifying finance when the finance step finishes, while the process continues to later steps.
Use this rule to decide where an action belongs:
- It should happen exactly once per request, at the end: final approval or final rejection set.
- It should happen at one specific stage: step-level action.
- It should happen on the way in or on withdrawal: initial submission or recall set.
A worked design: discount approvals
Suppose an Opportunity needs approval when Discount_Percent__c is above 20. The record has a custom picklist Approval_Status__c with values Draft, Submitted, Approved, Rejected.
| Action set | Actions |
|---|---|
| Initial submission | Field update: status to Submitted. Lock record. |
| Final approval | Field update: status to Approved. Email alert to owner. Keep locked. |
| Final rejection | Field update: status to Rejected. Email alert to owner. Unlock. |
| Recall | Field update: status to Draft. Unlock. |
Every path that ends the request sets the status field to a final value. No state is left showing Submitted. This is the main design check for the chapter: list each way a request can end (approved, rejected, recalled) and confirm each has a status update.
Recalling from Apex
The Apex Approval API treats a recall as a work item action with the value Removed. Recall actions configured on the process run just as they do from the UI. The next example finds the pending work item for a record and removes it.
public with sharing class ApprovalRecaller {
public static Boolean recall(Id recordId) {
List<ProcessInstanceWorkitem> items = [
SELECT Id
FROM ProcessInstanceWorkitem
WHERE ProcessInstance.TargetObjectId = :recordId
AND ProcessInstance.Status = 'Pending'
LIMIT 1
];
if (items.isEmpty()) {
return false; // nothing pending, nothing to recall
}
Approval.ProcessWorkitemRequest req = new Approval.ProcessWorkitemRequest();
req.setWorkitemId(items[0].Id);
req.setAction('Removed');
req.setComments('Recalled: discount changed.');
Approval.ProcessResult result = Approval.process(req);
return result.isSuccess();
}
}Compare this with the approve and reject example from the Apex chapter. The only difference is the action string: Approve, Reject, or Removed.
Common errors
- Status stuck on Submitted. A path (usually recall, or a step that returns to the previous approver) has no field update.
- Field update fails. The target picklist value does not exist, or the field is not writable by the update. A failed action can cause the submit, approve, or reject operation itself to error, so test each set.
- Rejection actions do not run. The step is set to go back to the previous approver.
- Action runs too early. It was placed in a step-level set when it belongs in the final set.
- Duplicate emails. The approver already receives the standard request notification, and an initial submission email alert targets the same person.
- Unexpected automation. Field updates made by approval actions are ordinary saves. Triggers and record-triggered flows on the object can fire, so check them if a status change causes side effects.
Exercise
A three-step approval process sets ApprovalStatusc to Approved in its final approval actions. Step two is configured so a rejection sends the request back to step one's approvers. A step-two approver rejects the request. Which action sets run, and what does the ApprovalStatus__c field show?
Show answer
No final rejection actions run, because the rejection sends the request back instead of ending the process. Final approval actions do not run either, since the process did not finish. Only the actions you configured at step level for rejection, if any, run. The field keeps whatever value the initial submission set gave it (for example Submitted), unless a step-level rejection action changes it. To show a different status, add a step-level rejection field update.
Exercise
Write the Apex action string and the object you query to recall a pending approval request, and explain which action set runs.
Show answer
Query ProcessInstanceWorkitem for the pending request on the target record, then call Approval.process with a ProcessWorkitemRequest whose action is 'Removed'. The recall actions run, not the final rejection or final approval actions.