0

I've a Batch class RecordsUpsertBatch whose job is to Process the Account's Child records. In some scenario I was hitting that batch twice/multiple times back-to-back for the same Account's child list and was getting the LOCK RECORD error. To over come this issue I've added the new method to check the transaction of RecordsUpsertBatch class and if the batch already has a Job I'm Scheduling the same batch with the help of a Scheduler class. This way my LOCK RECORD issue got resolved because my batch is in Queue for the next run.

In other scenario my Parent Accounts are different and so my Child list will be different too. This time batch will not throw the LOCK RECORD error because of the different child lists. But, when I'm hitting the same batch for other Account's Child list then also my batch is getting to the Queue because of the above Scheduler logic.

Need help here to Schedule the batch call for same Parent but Run it without Scheduler if the Parent Account are different.

Thanks in Advance, Ashu

0

You can try to handle this scenario using some custom logic. For example: 1. Create a Custom Setting with a Text Area field 2. Before executing your batch class just add you Account Id in the Text Area field. 3. For the next run first, check if current account id already exists in the text area field then schedule the batch to run in future or if it doesn't exist then execute the batch. 4. In the Finish method of the batch, remove the Account Id from the Text Area field.

This way you can run batches for different Account Id simultaneously and schedule it to run in the future for same Account Id.

Just keep in mind that Text Area character limit is 255 character only, so if you have lots of accounts to process simultaneously then handle it accordingly.

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.