0

We have a master detail relation from custom Invoice object to Account. There are bunch of roll-up summary fields on account calculated from invoice.

Other than roll up no where we have logic in triggers/ config where update of invoice record updates account record.

Issue: Lets say I have 2 accounts; A1 (Related invoice records: I1, I2, i3, I4) and A2 (Related invoice records: I5, I6, i7, I8). There is a nightly batch which grabs all invoice records (more than 1 million) and copies a formula field on invoice record to a static field on invoice itself.

Formula field on invoice record : Today() - CreatedDate

Once the batch runs nightly, we are getting this error. getMessage=unable to obtain exclusive access to this record or 83 records:

What I am assuming is when invoice record I4 is updated, rollup on Account record A1 are updated and when I3 is updated, system is not getting exclusive access on the parent record as it is the parent account records that are getting locked

Is my assumption correct? If yes/ no, can someone point me in right direction.

  • Ask support if they can run the record locking diagnostics tools (dashboard, really) on your org - have timestamps of when you hit this error handy so they know when to look. – ca_peterson Aug 9 '17 at 3:25
  • I have the timestamp of when these errors are happening as I am using database.saveresult and if not is success I am creating a record in error logger object. So I have timestamps... contact support with these timestamps and ask them to run diagnostic tools ? – sf_user Aug 9 '17 at 3:29
1

Yes, your assumption is correct.

Your batch job is processing the operation from multiple threads and it is trying to lock the same parent record because of rollup summary on Account object.

Workaround will be, limit the batch size and process the records in Serial mode, rather than parallel, so that system can obtain exclusive lock on Parent account.

Refer The Salesforce Bulk API - Maximizing Parallelism and Throughput Performance When Integrating or Loading Large Data Volumes for more information.

  • Thanks Boral for clarifying. Is there a keyword or how can we specify batch to run in serial mode rather than parallel ? – sf_user Aug 9 '17 at 0:15
  • 1
    Refer developer.salesforce.com/page/… – Santanu Boral Aug 9 '17 at 0:24
  • I went through the documentation but unable to understand where exactly in my batch class should I make that change to change the concurrency mode from parallel to serial – sf_user Aug 9 '17 at 3:13
  • you can put a separate question, with your code. You need to change the concurrencyMode as Serial – Santanu Boral Aug 9 '17 at 3:19
  • @SantanuBoral Batch jobs are not parallel, ever, today. (I work for Salesforce and once asked the team who built batch about this) – ca_peterson Aug 9 '17 at 3:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.