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
MWelch_WTMWelch_WT 

UNABLE_TO_LOCK_ROW with @future calls

I've got a trigger that potentially updates hundreds of opportunity records, with input from possibly thousands of records from other objects. So I've resorted to a future call to get around the query limits.

 

I thought this was a good solution, until I got an UNABLE_TO_LOCK_ROW error during the execution of one of these triggers. I'm assuming that this is because, when the @future call got to the record in question, it was, by an amazing coincidence, being updated by another user or trigger.

 

My two questions:

 

1: How do I get around this problem? This trigger's only been in place for a day, and I've already gotten the error, so I expect to see it again. More broadly, is @future the right route for my situation?

 

2: Was only the one opportunity update not executed, or did the entire @future call fail? The text of the failure ("Failed to invoke future method 'public static void acctBasedUpdate(LIST:String, LIST:String)" ) makes it seem like the entire @future call failed.

 

Thanks. 

Message Edited by MWelch_WT on 03-09-2010 07:18 AM
Anand@SAASAnand@SAAS

1. Apex batch is a better solution. You can find more information here

2. The issue you are seeing is due to concurrency wherein some other process has the specific record open for update and your @future process is trying to update the same process. More often when you reprocess the record this error will go away.

 

You would want to put some level of exception handling so that you can handle these situations more gracefully.