Skip to main content
Howdy Salesforce developers

I'm getting this error often. I'm running my batches in queue.

Any one have any idea how can we prevent this error. This error occur when Single record try to update by 2 jobs at same time.

Update failed. First exception on row 0 with id a145000000C6g5HAAR; first error: UNABLE_TO_LOCK_ROW, unable to obtain exclusive access to this record or 1 records: a145000000C6g5HAAR: []
12 Antworten
  1. 20. Jan. 2017, 09:54
    Hi Amrender,

    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 untill the locking on the record is released and then perform the required operaiton. 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

    kindly mark it as an answer if that resolves your query !

     
0/9000