You need to sign in to do that
Don't have an account?
Tommy Georgiou
Mass update quote line items error
Hi all,
I have created triggers for Quote Line Items where it checks a checkbox as soon as the Product Family of the item equals the value that I've set for each trigger.
One of the triggers looks like :
Now I am trying to update all the records in order to get teh boxes checked and I am getting an error like
Any Ideas how can I resolve this?
I have created triggers for Quote Line Items where it checks a checkbox as soon as the Product Family of the item equals the value that I've set for each trigger.
One of the triggers looks like :
trigger UpdateQuoteCheckBoxCake on QuoteLineItem (after insert, after update) { List<Quote> quoteList = new List<Quote>(); for(QuoteLineItem currQli : Trigger.New) { if(currQli.Product_Family__c == 'Cakes') { quoteList.add(new Quote(Id = currQli.QuoteId, Cakes__c = true)); } } if(!quoteList.isEmpty()) { update quoteList; } }
Now I am trying to update all the records in order to get teh boxes checked and I am getting an error like
Apex trigger UpdateQuoteCheckBoxReception caused an unexpected exception, contact your administrator: UpdateQuoteCheckBoxReception: execution of AfterUpdate caused by: System.ListException: Duplicate id in list: 0Q0w0000000o68RCAQ: Trigger.UpdateQuoteCheckBoxReception: line 15, column 1
Any Ideas how can I resolve this?
Plese use map insetad of list
map<Id, Quote> mapQuoteIdtoQuote = new map<Id, Quote>();
mapQuoteIdtoQuote.put(currQli.QuoteId, new Quote(Id = currQli.QuoteId, Cakes__c = true));
update mapQuoteIdtoQuote.values();
replace your list with maps..
Please check with this and let me know if this solve your issue..
P.S. If my answer helps you to solve your problem please mark it as best answer. It will help other to find best answer.
Thanks,
Sandeep
Salesforce Certified Developer
All Answers
You don't need to use update DML in trigger for same object. If you change any field value it should change it permanently. Using DML is trigger may cause runtime Error.
Suggested changes. Regards
You want to update the Quote or Quote line items based on your req ??
Please let me know your req so I can help you out on this..
Based on your above code it is throwing error because list where you are storuing the IDs having duplicate IDs..
Many QuoteLineItems can have same Quote as parent so it will throw an error..you can use map here or check if list already contains the id then dont add them....
P.S. If my answer helps you to solve your problem please mark it as best answer. It will help other to find best answer.
Thanks,
Sandeep
Salesforce Certified Developer
Will try and see.
Hi Sandeep,
My checkboxes are on the Quote so I want them to become checked based on the triggers that are structed for Quote Line Items. So I figured out that by updating the Items my boxes will become checked .
Sandeep is right. You can use Set collection instead of List to solve this issue. You need to convert set to list again while using in update though.
Regards,
Tried your solution but it's not working. The checkboxes are designed as Quote fields and not as Quote Line Items ones.
Plese use map insetad of list
map<Id, Quote> mapQuoteIdtoQuote = new map<Id, Quote>();
mapQuoteIdtoQuote.put(currQli.QuoteId, new Quote(Id = currQli.QuoteId, Cakes__c = true));
update mapQuoteIdtoQuote.values();
replace your list with maps..
Please check with this and let me know if this solve your issue..
P.S. If my answer helps you to solve your problem please mark it as best answer. It will help other to find best answer.
Thanks,
Sandeep
Salesforce Certified Developer
Now the trigger is
based on this I get the following error :Error: Compile Error: Variable does not exist: currQli.QuoteId at line 6 column 23
Please replace your code with this
trigger UpdateQuoteCheckBoxCake on QuoteLineItem (after insert, after update)
{
map<Id, Quote> mapQuoteIdtoQuote = new map<Id, Quote>();
for(QuoteLineItem currQli : Trigger.New)
{
if(currQli.Product_Family__c == 'Cakes')
{
mapQuoteIdtoQuote.put(currQli.QuoteId, new Quote(Id = currQli.QuoteId, Cakes__c = true));
}
}
if(!mapQuoteIdtoQuote.isEmpty())
{
update mapQuoteIdtoQuote.values();
}
}
Please replace this and let me know if it solves your problem
P.S. If my answer helps you to solve your problem please mark it as best answer. It will help other to find best answer.
Thanks,
Sandeep
Salesforce Certified Developer
Please try the ablove code and let me know if that solves your issue.
P.S. If my answer helps you to solve your problem please mark it as best answer. It will help other to find best answer.
Thanks,
Sandeep
Salesforce Certified Developer
I am trying now to deploy this onto production and try and update the quote line items to see if it works. Will let you know in a bit
It seems that with the new trigger I need to change the test class as well because I am covering the code up to 71% only.
My test class is :
Any Ideas why it won't cover up to 100%?
QuoteLineItem which you are inserting should have
Product_Family__c == 'Cakes'
Please add this and check..
I am trying to get that on the but it wont save Compile Error: expecting an equals sign, found '==' at line 35 column 167
then I remove one of the = and the error is
Error: Compile Error: Field is not writeable: QuoteLineItem.Product_Family__c at line 35 column 170
You dont have write permision for this field, please check the setting for this as it is custom field..give the eprmission and then check again...chck your profile also..
Found the problem. It was on the trigger where I mispelled the Product Family
great! now try and let me know if you are able to deploy.
Works like a charm
Feel free to reach out for all your queries..