Activity Forums Salesforce Questions and Answers How to handle row locks in Salesforce Apex Batch Jobs?

  • How to handle row locks in Salesforce Apex Batch Jobs?

  • Jagannath Kasula

    January 18, 2019 at 5:32 pm


    I am writing complex batch job which runs for every hour and adds contacts to CampaignMember object, at the same time some other batch jobs are updating contacts in Campainmember object. Due to this we are encountering row locks and because of this row locks few records are not getting updated. Can any one suggest better solution other than using [select id from campaign limit 1 for update]

    Thank you,


  • Jade

    January 29, 2019 at 5:40 am

    When a record is being updated or created, Salesforce puts a lock on that record to prevent another operation from updating the record at the same time and causing inconsistencies on the data.

    These locks normally last for a few seconds and when the lock is released. If you are facing the same problem then please pay attention to the following concepts :

    Data Skew

    Record Lock ChestSheet 

Viewing 1 - 2 of 2 posts

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos