Sub topic 9
How record locking works during approval
This chapter assumes you can build a basic approval process and know profiles, permission sets, and the difference between a user's edit access and an administrator's. Record locking is what keeps a record stable while approvers decide on it.
What locking does
When a record is submitted for approval, Salesforce locks it. Most users can no longer edit it, and they can't change related fields that the approval depends on. The lock protects the approver from reviewing data that changes underneath them.
The lock applies from the moment of submission until the process reaches a final approval or final rejection, or until the submitter recalls the request.
Who can edit a locked record
Locking does not block everyone equally. Which users can still edit depends on the process's Record Editability Properties setting.
| Setting | Who can edit while locked |
|---|---|
| Administrators only | System administrators (and users with the "Modify All Data" permission). The current approver can't edit. |
| Administrators or the currently assigned approver | The same administrators, plus the user the request is currently assigned to. |
The approver's ability to edit is useful when they need to correct a value, such as a discount, before approving. Choose the setting when you create the process, and review it before activating.
Locking is enforced on edits by users and by automation. A flow, Apex trigger, or API call that updates a locked record by a user without the right access fails with an error such as ENTITY_IS_LOCKED.
Opportunity opp = [SELECT Id, Amount FROM Opportunity WHERE Id = :opportunityId];
System.debug('Locked: ' + Approval.isLocked(opp.Id));Approval.isLocked returns true while the record is locked. Approval.lock and Approval.unlock change the state from code, and both return a result you can check for errors. Running code needs the right access, so test it as a normal user.
The lock life cycle
By default, the process locks the record on submission. It unlocks on final rejection and on recall. On final approval, the record stays locked unless you choose otherwise. That default is correct for many cases, such as an approved contract that should no longer change, but surprises people who expect editing to resume.
Controlling the lock with actions
You set lock behavior in the process's actions:
- Initial submission actions: the record is locked automatically. You can't turn this off.
- Final approval actions: choose Lock the record from being edited or Unlock the record if you want to allow later changes.
- Final rejection and recall actions: the record is unlocked by default.
Field updates that run as approval actions can change a locked record. That is how a process sets a status such as Approved without needing an unlock first.
Unlocking by hand
An administrator can unlock a record from the Approval History related list by using the Unlock Record button, or through the API. This is useful when an approval is stuck, for example when an approver has left the company and nobody can act on the request. After unlocking, the pending request still exists, so a stuck request may also need to be reassigned or recalled.
Common errors
- "Record is locked" on save: a trigger or flow runs as a user who can't edit locked records. Check who is allowed to edit under the record editability setting.
- Record stays locked after approval: the final approval action leaves the lock in place. Add the unlock action if edits must resume.
- Approver can't edit: the process uses the administrators-only setting.
Exercise
A sales rep submits an opportunity for approval. The manager approves it, but the rep reports the opportunity is still read-only. The process is configured with default final approval actions. Why does this happen, and how would you let the rep edit again?
Show answer
By default, final approval leaves the record locked. Add the "Unlock the record" action to the final approval actions. A system administrator can also unlock a single record manually.