
The lock gets released when the transaction completes. When two users or two different apex code tries to update the same record, then salesforce throws an error “UNABLE_TO_LOCK_ROW unable to obtain exclusive access to this record”. Using FOR UPDATE keyword helps to achieve a lock a client end to prevent this locking issues.
- Go to Background Jobs under setup and check whether any Sharing Rule Calculation or Picklist field list of value change is happening. ...
- Other user may also work on the same record at the same time.
What is the use of lock () function in Salesforce?
It will ensure that the record is locked and no other job can update the same record at that point in time. The conflicting job will then wait untill the locking on the record is released and then perform the required operaiton.
How to fix unable_to_lock_row error in Salesforce?
You try to update the same record in your code and gets UNABLE_TO_LOCK_ROW error as the record is already locked. You just need to get the locked record Id and find out the second flow which is updating this record at the same time.
What is wrong with salesrecords object in Salesforce?
The SalesRecords object does not have any trigger on it and is a child of another object Sales. The Sales object has some rollup fields which are summing up fields from SalesRecords object. Lately, we are getting the below error for some of the records which are updated. UNABLE_TO_LOCK_ROW, unable to obtain exclusive access to this record
What happens to the same record when Salesforce update?
When salesforce updating any record, it prevents to update the same record using UI or through code i.e. that record gets locked. The lock gets released when the transaction completes.

How do I stop a record lock error in Salesforce?
To prevent this, you can do either of the following:Reduce the batch size.Process the records in Serial mode instead of parallel, that way one batch is processed at a time.More items...
How do I lock an apex record in Salesforce?
go to Setup | Search Automation Settings in the Quick Find box | click on Automation Settings. Then, select Enable record locking and unlocking in Apex.
What causes record locking in Salesforce?
Just like most relational database systems, Salesforce locks records when they are being modified, to prevent two people from updating the same record simultaneously, which would result in a conflict.
How do you lock the records from being edited by others in SOQL?
To lock records, simply use the FOR UPDATE keywords in your SOQL statements. You do not have to manually commit the records so if your Apex script finishes successfully the changes are automatically committed to the database and the locks are released.
How can we avoid deadlock in Apex?
To avoid such deadlocks, the Apex runtime engine:First locks sObject parent records, then children.Locks sObject records in order of ID when multiple records of the same type are being edited.
How do I lock record in approval process?
Previously, you could set approval-process locks and unlocks only through the Salesforce user interface. To enable this feature, from Setup, enter Process Automation Settings in the Quick Find box, then click Process Automation Settings. Then, select Enable record locking and unlocking in Apex. The new Approval.
Who can edit locked records in Salesforce?
Administrators OR... Lets the assigned approver and admins edit the record. Even when a campaign is locked for approval, users can add campaign members to it.
What is granular locking in Salesforce?
By default, the Lightning Platform platform locks the entire group membership table to protect data integrity when Salesforce makes changes to roles and groups. This locking makes it impossible to process group changes in multiple threads to increase throughput on updates.
How do I lock a row in SOQL?
The lock gets released when the transaction completes. To lock a set of sObject records in Apex, embed the keywords FOR UPDATE after any inline SOQL statement.
How do you make a record Uneditable in Salesforce?
Using Record Type & Page Layouts: Create two different record types say “Open” & “Locked” and change the record type of the record using workflow field update or trigger. And then create a separate page layout for the “Locked” record type with all fields marked as 'Read-Only'.
How do you make record read only just after creation no one can edit it not even creator in Salesforce?
We can Achieve this by using workflows rules. First create a new record type as a "Rean only", it has only read only permission to all profiles . next create workflow on status field. if "status" is changed to "Closed" we can update the record type field.
How do I deal with too many SOQL queries?
Resolve the "Too many SOQL queries: 101" error To fix the issue, change your code so that the number of SOQL fired is less than 100. If you need to change the context, you can use @future annotation which will run the code asynchronously.