Activity Forums Salesforce® Discussions How to handle row locks in Salesforce Apex Batch Jobs?

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

    Posted by Jagannath Kasula on January 18, 2019 at 5:32 pm

    Hello,

    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,

    Jagannath

    Jade replied 5 years, 10 months ago 2 Members · 1 Reply
  • 1 Reply
  • Jade

    Member
    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 

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos