Developer script exception from Nicomatic : quotepotential : quotepotential: execution of AfterUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id a0Q90000005Q9RWEA0; first error: UNABLE_TO_LOCK_ROW, unable to obtain exclusive access to this record: [] Trigger.quotepotential: line 17, column 1
caused by: System.DmlException: Update failed. First exception on row 0 with id a0Q90000005Q9RWEA0; first error: UNABLE_TO_LOCK_ROW, unable to obtain exclusive access to this record: []
Trigger.quotepotential: line 17, column 1
this is my Trigger:
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 IN :quoteIds GROUP BY Quote1__c]) {
Quote__C qu=new quote__c();
qu.id=(Id)ar.get('Quote1__c');
qu.Potential__c=(Decimal)ar.get('sumMax');
quotes.add(qu);
}
if(quotes.isempty() == false)
{
update quotes;
}
}
we have one more button in quote email template at the time click this button i am getting exception to my mail.
the function of quote email template it will send the quote pdf into email which sending to other user
I have used the future method but i am not getting the value
hi this is the old trigger i am sending you
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 IN :quoteIds GROUP BY Quote1__c]) {
Quote__C qu=new quote__c();
qu.id=(Id)ar.get('Quote1__c');
qu.Potential__c=(Decimal)ar.get('sumMax');
quotes.add(qu);
}
if(quotes.isempty() == false)
{
update quotes;
}
}
this was the new trigger with future method but not working
trigger quotepotential on Quote_Line_Item__c (after insert,after update) {
Set<id> uniqueNames=new Set<id>();
for(Quote_Line_Item__c a :Trigger.new) {
if(a.IsFutureContext__c) {
a.IsFutureContext__c = true;
} else {
uniqueNames.add(a.id);
}
}
if(!uniqueNames.isEmpty())
asyncApex.processAccounts(uniqueNames);
}
global class asyncApex {
@future
public static void processAccounts(set<id> id) {
Set<Id> quoteIds = new Set<Id>();
List<Quote__c> quotes = new List<Quote__c>();
for (Quote_line_item__c a : [Select Id, Name, IsFutureContext__c From Quote_line_item__c where ID IN :ID]) {
a.IsFutureContext__c = true;
if (a.Quote1__c != null){
quoteIds.add(a.Quote1__c);
}
for(AggregateResult ar:[SELECT Quote1__c , SUM(Max_Batch__c)sumMax FROM Quote_Line_Item__c WHERE Quote1__c IN :quoteIds GROUP BY Quote1__c]) {
Quote__C qu=new quote__c();
qu.id=(Id)ar.get('Quote1__c');
qu.Potential__c=(Decimal)ar.get('sumMax');
quotes.add(qu);
}
if(quotes.isempty() == false)
{
update quotes;
}
}
}
}
can you correct this one .