2

This is a generic question which I couldn't find enough data online. I have a batch job that runs once every week. This job updates Contact records based on updates on the parent Account.

Scenario: For instance, if the batch job started executing at 4:00 Am PST. And by scope has almost 100,000 Contacts. One random user opens a Contact record at around 4:01 Am PST, which is already in the batch's scope but yet to get executed (future batch chunk), and commit to the database.

Questions:

  1. Will the Contact record get updated (committed to the database) with the changes from the user and comes out of the batch's scope?
  2. Contact gets updated with user changes, but still remains in the batch's scope and get executed and recommitted to the database with new changes based on previous Contact value?
  3. Contact gets updated with user changes, but still remains in the batch's scope and get executed and recommitted to the database with new changes based on the new updates(from user) that exist in the database?
1
  • 3
    I think you should find answers to these questions here.
    – Phil W
    Commented Jul 21, 2020 at 22:26

1 Answer 1

1

Your records in the execute block will be stale. You retrieved a Database.QueryLocator in the start method, and records will be chunked as if you queried them all at that time. However, these updates from the user will not remove the record from the QueryLocator either, it will still get chunked eventually. So if you just re-query the records in your execute block, your batch should work more or less intuitively.

2
  • Hi Adrian, your answer made my head spin :) So, my #3 will be the valid scenario: Contact gets updated with user changes, but still remains in the batch's scope and get executed and recommitted to the database with new changes based on the new updates(from user) that exist in the database? Commented Jul 22, 2020 at 20:39
  • 1
    That's correct.
    – Adrian Larson
    Commented Jul 22, 2020 at 20:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .