22

Error Message:

Developer script exception from Nicomatic : quotepotential : quotepotential: execution of AfterUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id a0Q90000005PoxtEAC; first error: UNABLE_TO_LOCK_ROW, unable to obtain exclusive access to this record: [] Trigger.quotepotential: line 14, column 1

Apex script unhandled trigger exception by user/organization: 00590000001A6jh/00D90000000bovq

quotepotential: execution of AfterUpdate

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

Trigger.quotepotential: line 14, column 1

these mails are getting to my mail..........

trigger quotepotential on Quote_Line_Item__c (after insert,after update) {
Set<Id> quoteIds = new Set<Id>();
List<Quote__c> quotes = new List<Quote__c>();
for (Quote_Line_Item__c record: Trigger.new) {
    if (record.Quote1__c != null){
        quoteIds.add(record.Quote1__c);
    }
}
for(AggregateResult ar:[
            SELECT 
                Quote1__c, 
                SUM(Max_Batch__c)sumMax 
            FROM Quote_Line_Item__c 
            WHERE Quote1__c=:quoteIds 
            GROUP BY Quote1__c
            ]) {
     quotes.add(new Quote__c(
         Id=(Id) ar.get('Quote1__c'),
         Potential__c = (Decimal) ar.get('sumMax')
         ));
  }
  if (quotes.isempty() == false) {
      update quotes;
  }

}

  • It is happening everytime this piece of code is run? – BarCotter Nov 19 '13 at 11:45
  • no only certain times – Teja Nov 19 '13 at 12:06
  • The Mohith Kumars answer is most likely correct. Other users are updating a record that you are also trying to update – BarCotter Nov 19 '13 at 12:07
39

http://www.salesforce.com/us/developer/docs/apexcode/Content/langCon_apex_locking_statements.htm

ROW_LOCK issue is very common if you have multiple users updating the record at the same time .Or say a batch job is running and is updating a record and same record another trigger or code snippet (usually a future method) is updating.

Account [] accts = [SELECT Id FROM Account LIMIT 2 FOR UPDATE];

Using FOR UPDATE keyword helps to achieve a lock a client end to prevent this locking issues .

Here is a small article on sharing model to avoid this granular locking

https://help.salesforce.com/apex/HTViewSolution?urlname=How-can-I-avoid-getting-lock-errors-in-my-organization-1327109108393&language=en_US

http://blogs.developerforce.com/engineering/2013/01/reducing-lock-contention-by-avoiding-account-data-skews.html

Also read on data skews which may be another cause .

  • what can i do to get rid of this error – Teja Nov 19 '13 at 11:36
  • If the issue was because other users are updating the record that your trigger is trying to update then the error should no longer be happening, assuming no one else is editing Quote__c records. – BarCotter Nov 19 '13 at 11:51
  • I am also getting same problem, if i put FOR UPDATE is it enough to get rid out of this or need i put any other code... – Sunny Dec 30 '13 at 5:40

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.