Saturday 20 July 2019

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


Solution:

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. The conflicting job will then wait until the locking on the record is released and then perform the required operation. 

This will avoid conflicts between jobs that are running concurrently and will not throw up this exception. 


You can refer the below link to learn more about record locking.

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_locking_statements.htm

No comments:

Post a Comment