I'm trying to debug a the following error:
UNABLE_TO_LOCK_ROW, unable to obtain exclusive access to this record: []
The error occurs when a method is called to create a task when an order fulfillment is submitted.
Here is the code:
private void createTasks() {
List<Task> tasksToInsert = new List<Task>();
for(Fulfillment_Recipient__c r : recipientList) {
Task task = new Task();
task.ActivityDate = Date.today();
task.Status = 'Completed';
task.Subject = 'Content Ordered';
task.Type = 'Fulfillment Order';
task.whoId = r.Contact__c;
task.whatId = r.Order_Fulfillment__c;
tasksToInsert.add(task);
}
if(!tasksToInsert.isEmpty() && tasksToInsert.size() > 0) {
insert tasksToInsert;
}
}
The error occurs on this line:
insert tasksToInsert;
I've looked thru the logs and I can't see what is locking the record to stop the insert from happening.
Is there a way to capture additional log entries to see if there are any asynchronous/future logs spawned between the insertion of the task record? I'm wondering if there is an integration process that might be causing the lock or some other process?
I'm stumped on how to isolate the cause of this error.
Thanks for any suggestions.
if(!tasksToInsert.isEmpty() && tasksToInsert.size() > 0)is unnecessary, others have proven that if the list is empty, no DML attempt is even made so no governor limit is burned. – cropredy Nov 01 '14 at 00:09