0

I have a trigger written on before update of account that whenever a check box field on account object is updated from false to true, then I am doing some actions on the related cases.

We have a daily batch job also that runs everyday and pick up those accounts who have the same check box field set to true and do some update on the related cases.

My question is at the same time if the flag on account is set to true and batch runs immediately after this, then trigger is also invoked at the same time. Will there be any conflict as batch will try to update the related cases and trigger will also try to update the related cases?

1 Answer 1

2

In database terminology, when a record is updated, there's a "lock" that is set so concurrent updates won't clobber each other. Salesforce does allow some wiggle room, about five to ten seconds, before failing to acquire the lock, however. So, either both updates will succeed, or one will fail (whichever one tried to get the lock last). If it fails, an error message will be generated in a log somewhere. To help avoid this problem in your batch, make sure you use locking statements (select Id from account where ... For update). Note that a record in a trigger is already locked, so the batch class would be the only thing waiting to acquire the lock.

1

You must log in to answer this question.

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