function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
JBabuJBabu 

UNABLE_TO_LOCK_ROW, unable to obtain exclusive access to this record

 

Hi,

 

I have a scheduled job which fires 2 chatter batch jobs. Both use the same opportunity and try to insert in to chatter "FeedItem" table separately.

 

I am getting below issue:

 

Failed to process batch for class 'OpportunityChatterBatchJob1' for job id '707C000000Id6tz'

 

caused by: System.DmlException: Insert failed. First exception on row 0; first error: UNABLE_TO_LOCK_ROW, unable to obtain exclusive access to this record: []

 

 

I am thinking the issue could be because both batch jobs are trying to use same opportunity id for their feeds.

 

I cannot fire these jobs separately because for that I have to create an extra scheduled job.

 

Please let me know if my analysis of the issue is correct. 

Is there any alternative to stop this error from occuring in the case of 2 batch jobs scheduled at same time?

or having an extra scheduled job is the only alternative?

 

Thanks,

Babu.

Best Answer chosen by Admin (Salesforce Developers) 
RoyGiladRoyGilad

Hi

 

You could serialize the Batches

 See the link below:

http://developer.force.com/cookbook/recipe/serialize-batch-apex

 

Hope that helps,

Roy Gilad

All Answers

RoyGiladRoyGilad

Hi

 

You could serialize the Batches

 See the link below:

http://developer.force.com/cookbook/recipe/serialize-batch-apex

 

Hope that helps,

Roy Gilad

This was selected as the best answer
JBabuJBabu

Thank you..

 

Also just wanted to add a point, one batch job can be called thru other as per winter 13 release.

 

Thanks,

Babu.