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 1Apex script unhandled trigger exception by user/organization:
00590000001A6jh/00D90000000bovqquotepotential: 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;
}
}
Best Answer
Salesforce platform has a feature ROW LEVEL Security. This feature ensures that sharing and visibility set by salesforce administrators for the records have to be maintained. As a part of this feature, there are sharing calculations that the platform has to perform when the record ownership is changed or child records are created/modified.
A record can also go into a Locked State if it is a parent and part of master-detail relationships and child records are getting saved/updated.
You can read how apex can prevent such locks using the link here
Here are some helpful articles on how to design your sharing model to avoid 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
You can prevent using the below techniques