How to avoid unable to lock row error?

How to avoid unable to lock row error?

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.

How are debug logs used in process builder?

Debug Logs allow us to to see everything that happened during the Save process of a record. Need a refresher on what the Order of Execution is, check it out here. You’ll find Processes as #13 on that list. That means by reading the Debug Log I am able to see if my Process actually was triggered or if it didn’t meet the criteria.

How to troubleshoot visual flow and process builder?

The Fault Emails are great and solve close to 90% of the Flow and Process Builder errors that I have. However, sometimes it just isn’t that simple. A Quick Recap …

When to use fault emails in process builder?

You can checkout the first post on using the Fault Emails here. The Fault Emails are great and solve close to 90% of the Flow and Process Builder errors that I have. However, sometimes it just isn’t that simple. A Quick Recap … When I’m looking to fix a Flow there are typically three routes that I use:

What does unable to lock row Mean in Salesforce?

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.

How to check for unable to lock row in apex?

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.

When do you need to lock a record?

When you have multiple jobs running that update the same set of records, it’s recommended to lock the records using the FOR UPDATE keyword. It will ensure that the record is locked and no other job can update the same record at that point in time.