Skip to content
Salesforce Dictionary - Free Salesforce GlossarySalesforce Dictionary
DictionaryRRecord Locking
AdministrationIntermediate

Record Locking

Record locking is the Salesforce mechanism that prevents a record from being edited while it sits in a controlled state, most commonly while it is pending approval or being updated by Apex.

§ 01

Definition

Record locking is the Salesforce mechanism that prevents a record from being edited while it sits in a controlled state, most commonly while it is pending approval or being updated by Apex. A locked record cannot be changed through the user interface or through code, except by users and processes that the lock allows.

The term covers two related behaviors. In approval processes and Flow, Salesforce locks a record when it is submitted for approval and releases the lock once the request is approved, rejected, or recalled. In Apex, the FOR UPDATE keyword locks the queried rows for the duration of the transaction so two operations cannot update the same data at the same time.

§ 02

How locking protects records, from approvals to Apex

Two kinds of locking under one name

People use the phrase record locking for two different features, and it helps to keep them separate. The first is approval locking. When a record enters an approval process, Salesforce locks it so the values cannot drift while approvers review the request. The second is row locking in Apex, controlled by the FOR UPDATE keyword on a SOQL query. That lock keeps two transactions from updating the same rows at the same moment. Both share a goal, which is protecting data while something important happens to it. They differ in scope and lifespan. Approval locks can persist for hours or days, for as long as the record stays in the approval queue. Apex FOR UPDATE locks last only for the current transaction and release as soon as it commits or rolls back. Approval locks are configured by admins through point and click settings. Apex locks are written by developers in code. Knowing which one you are dealing with tells you where to look when an edit is unexpectedly blocked, and which team owns the fix.

Locking during the approval lifecycle

When a user submits a record for approval, Salesforce locks it automatically. From that point, the record is read only for most users until the approval reaches a final state. The lock releases when the request is approved, rejected, or recalled by the submitter. If your approval process has several steps, the record stays locked across all of them, not just the first. Who can still edit a locked record depends on the Record Editability setting on the approval process. The default option is Administrators only, which means users with Modify All Data, or Modify All Records on that object, can unlock and edit. The second option also lets the currently assigned approver edit the record while it waits on them. This is useful when an approver needs to correct a small detail before deciding. One gotcha catches many admins. Changing Record Editability only affects records submitted after you save the change. Records already in flight keep the old behavior until they are recalled and resubmitted.

The Lock Record action in Flow

Approval processes are not the only way to lock records. Flow includes a Lock Record action, sometimes called Lock or Unlock Records, that lets an admin lock or unlock a record without an approval at all. You choose the record, pick whether to lock or unlock it, and the flow handles the rest. This is handy when business rules say a record should freeze once it reaches a certain status, for example an Opportunity that is Closed Won or an invoice that has been sent. The action gives you control that approvals alone do not. You can lock a record on a schedule, lock it as part of a larger automated process, or unlock it when a condition clears. Because it runs inside Flow, you can wrap it in decision logic and combine it with other actions in one transaction. Remember that a lock set this way behaves like any other record lock. The same people who can edit approval locked records, namely admins with the right permission, can still edit records locked by Flow.

Locking and unlocking from Apex

Developers can lock and unlock records in Apex once the org enables it. Under Setup, in Process Automation Settings, the option Enable record locking and unlocking in Apex turns this on. After that, the Approval class exposes lock and unlock methods. You can call Approval.lock with a single Id, a list of Ids, an sObject, or a list of sObjects, and an optional Boolean controls whether partial success is allowed. The matching Approval.unlock methods reverse it. These calls behave like DML. They count against your DML statement limits, they are blocked before a callout in the same transaction, and they roll back if the transaction fails. Each call returns a LockResult, or a list of them, so you can inspect which records locked and which failed and why. This API is the right tool when locking needs to follow logic that point and click cannot express, such as locking related child records when a parent is approved, or locking based on a calculation. Treat lock changes with the same care you give any DML in a trigger or batch job.

FOR UPDATE and the UNABLE_TO_LOCK_ROW error

The Apex FOR UPDATE keyword is a different mechanism, aimed at concurrency rather than approvals. You add it to the end of a SOQL query, as in [SELECT Id, Amount FROM Opportunity WHERE Id = :oppId FOR UPDATE]. Salesforce then locks those rows so no other client can update them until your transaction finishes. Use it when two jobs might read the same record, calculate a new value, and write back, because without a lock one update can silently overwrite the other. This locking is also the source of the UNABLE_TO_LOCK_ROW error. That error appears when one process tries to update a record that another process already holds a lock on. Common causes include parallel batch jobs touching the same parents, or roll up summary recalculation colliding with your DML. One firm rule worth memorizing. You cannot use an ORDER BY clause in a SOQL query that has a FOR UPDATE clause. Ordering and row locking do not combine, so drop the ORDER BY or sort the list in Apex after the query returns.

Designing approvals that respect the lock

Locking is a feature, not a bug, but it surprises users who expect to edit a record any time. Good design starts with telling people why a record is read only. A help text note, a custom status field, or a screen flow message that says the record is locked for approval prevents a flood of confused cases to your admin team. Visibility turns a frustration into an understood rule. Decide deliberately whether approvers should be able to edit. The Administrators and the currently assigned approver option is convenient, yet it weakens the guarantee that values cannot change after submission. If your reason for locking is to freeze the amount a manager approves, you may want admins only and a recall path for genuine corrections. Build a clear process for those edits. Recall the request, make the change, and resubmit, so the approval is always decided on current data. Finally, audit who holds Modify All Data, because that permission quietly bypasses every record lock in the org and should be granted sparingly.

§ 03

How to configure record locking

There is no single switch named Record Locking. You configure it where the lock is created. For approvals, you set Record Editability on the approval process. For ad hoc locks, you use the Lock Record action in Flow. For code driven locks, you enable Apex locking. These steps cover the two most common admin paths.

  1. Open the approval process

    Go to Setup, then Approval Processes, and select the process for the object you want. Click into its detail page where the steps and settings live.

  2. Set Record Editability

    Edit the process and choose either Administrators ONLY can edit records during the approval process, or Administrators and the currently assigned approver can edit records. Save your choice.

  3. Reactivate and resubmit if needed

    If the process was already active with records in flight, recall and resubmit those records so the new editability setting applies to them.

  4. Add a Flow Lock Record action for non approval cases

    In Flow Builder, add the Lock Record action, choose the record, and set it to lock or unlock. Wrap it in decision logic so it fires only when your status condition is met.

  5. Enable Apex locking if developers need it

    In Setup, open Process Automation Settings and turn on Enable record locking and unlocking in Apex so the Approval.lock and Approval.unlock methods work.

Record Editabilityremember

Controls who can edit a record while it is locked for approval: administrators only, or administrators plus the currently assigned approver.

Lock Record actionremember

A Flow element that locks or unlocks a chosen record outside of any approval process, driven by your own automation rules.

Enable record locking and unlocking in Apexremember

A Process Automation Setting that activates the Approval.lock and Approval.unlock methods for developer driven locking.

Gotchas
  • Changing Record Editability only affects records submitted after the save; recall and resubmit anything already pending.
  • Users with Modify All Data or Modify All Records can edit any locked record, so audit those permissions.
  • Apex lock and unlock calls count as DML, are blocked before callouts, and roll back with the transaction.
  • A SOQL query that uses FOR UPDATE cannot include an ORDER BY clause; sort in Apex instead.

Prefer this walkthrough as its own page? How to Record Locking in Salesforce, step by step

§

Trust & references

Sources

Cross-checked against the following references.

Official documentation

Straight from the source - Salesforce's reference material on Record Locking.

Keep learning

Hands-on resources to go deeper on Record Locking.

Was this entry helpful?
Help us write better definitions. Quick reactions or detailed edit suggestions.

About the Author

Dipojjal Chakrabarti is a B2C Solution Architect with 29 Salesforce certifications and over 13 years in the Salesforce ecosystem. He runs salesforcedictionary.com to help admins, developers, architects, and cert/interview candidates sharpen their fundamentals. More about Dipojjal.

§

Test your knowledge

Q1. When does Salesforce Record Locking automatically lock a record in an approval process?

Q2. What problem does Record Locking during an approval process prevent?

Q3. Who can edit a record that Record Locking has locked during a pending approval?

§

Discussion

Loading…

Loading discussion…