function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Swiderski, ErikSwiderski, Erik 

UNABLE_TO_LOCK_ROW: unable to obtain exclusive access to this record or 1 records:

We constantly receive this error message for some of our flows and I'm not sure where to start with debugging it. The record ID referenced in the flow error email is always a record (not always the same one) that is a lookup field on one of the records to be created as part of the flow. Not really sure what info you folks need to assist me, let me know and I will post ASAP.
Anjita MaheshwariAnjita Maheshwari
Hi Erik,

What flow are you using to update the record? Is it a future method call, queueable or a batch process?

The reason of this error is to update same record by more than one transaction. Whenever a record is updated, salesforce places a lock on that record so that it could maintain data consistency and same record didn't get updated at the same time by some other transaction. 

In case of master-detail relationship, if we update detail record, it also locks a child record. So if you are updating child records of same master in different transactions, this may also lead to UNABLE_TO_LOCK_ROW error. 

Here you can find more detail of this error - https://help.salesforce.com/articleView?id=000229525&type=1

To start debugging the issue, create debug logs and also check Apex Jobs at the same time. Apex job will have asynchronous calls in your flow and must have some DML which is updating same record on which you are getting UNABLE_TO_LOCK_ROW error. You need to check both the updates, the update on which you are facing UNABLE_TO_LOCK_ROW error and the asynchronous method or class which is updating the same record. Please let me know in case of any concern.

Thanks,
Anjita
Swiderski, ErikSwiderski, Erik
Thanks for the quick reply, Anjita. I figured out that I still had a process builder action running that was trying to update the owner on the record when a record was created, so that was causing the unable to lock row error. In case I run into a similar issue in the future, could you direct me to some information that would help with creating a debug log? If I had a debug log that would've probably helped me significantly. :-)
Anjita MaheshwariAnjita Maheshwari
Hi Erik,

If you are able to reproduce the issue, then Apex jobs and Debug logs will help you to figure out the two DML calls on the same record. Apex jobs will have an asynchronous call which is already running and has put a lock on the record. 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. 

You can also check best practices to avoid this issue at https://help.salesforce.com/articleView?id=000229525&type=1. Please feel free to revert back if you have any query.

Thanks,
Anjita
Deanna Aaron 11Deanna Aaron 11
Hi Erik. Did you ever figure out how to resolve the "UNABLE_TO_LOCK_ROW error? We are running into the same issue with our process builder.
Swiderski, ErikSwiderski, Erik
We did not. I narrowed down the list of possible causes one particular apex job running at the same time. This apex job (find by going to Setup > search "Apex Jobs") was from a managed package that updates records in batches that was most likely locking the row. May not be the case for you, but sharing my findings in case it helps.