You need to sign in to do that
Don't have an account?
About Opportunity and Quote
i have written a trigger for updating the amount field value with quote total price when we selet the quote as primary.but it will work only when we adding single quotelinitem to the quote.When i am trying bulky quotelineitems at a time it will throw an exception " Apex trigger qlitem123 caused an unexpected exception, contact your administrator: qlitem123: execution of AfterInsert caused by: System.QueryException: List has more than 1 row for assignment to SObject: Trigger.qlitem123: line 3, column 28 "
my code is here:please help me to solve this problem
trigger qlitem123 on QuoteLineItem (after insert, after update) { public static double total=0; quotelineitem qli=[select id,quoteid,totalprice from quotelineitem where id in:Trigger.newMap.keyset()]; List<QuoteLineItem> qlil=new List<Quotelineitem>(); qlil.add(qli); quote q=[select id,opportunityid,totalprice,stage__c from quote where id=:qli.quoteid]; opportunity opp=[select id,amount from opportunity where id=:q.opportunityid]; List<opportunity> oppl=new List<opportunity>(); for(integer i=0;i<qlil.size();i++) { total=total+qlil[i].totalprice; } if(q.stage__c=='primary') { opp.amount=q.totalprice+total; } oppl.add(opp); update oppl; }
Thanks
Sreelekha
you are doing a mistake in the code
quotelineitem qli=[select id,quoteid,totalprice from quotelineitem where id in:Trigger.newMap.keyset()];
it should actually be
List<quotelineitem> qli=[select id,quoteid,totalprice from quotelineitem where id in:Trigger.newMap.keyset()];
and then you process further accordingly
Hi,
Thanks for reply
List<quotelineitem> qli=[select id,quoteid,totalprice from quotelineitem where id in:Trigger.newMap.keyset()];
i have written like that also.But i didn't get how to set qli.quoteid to quote for number of quote line items without loop.
quotelineitem qli=[select id,quoteid,totalprice from quotelineitem where id in:Trigger.newMap.keyset()];
List<QuoteLineItem> qlil=new List<Quotelineitem>();
qlil.add(qli);
Here when you are creating a quotelineitem object qli, your query is returning more than one resulting values, hence you are unable to assign it to the object variable. for more than one row, you need to assign it to a list.
what you can do is :
List<QuoteLineItem> qlil=new List<Quotelineitem>();
qlil = [select id,quoteid,totalprice from quotelineitem where id in:Trigger.newMap.keyset()];
No need to take a separate object and then add it to the list.
will that work for you?
incase of multiple records in your list, I don't think you can process it without a for loop.
How would you determing from which quotelineitem, your quote id is?
but i have the requirement to do this without writing any query inside for loop.I think it is possible through the map,set.But i could confused with them.if you know please reply me how to do.
try the following code. correct any syntax mistakes
Hi ,
Thanks for reply.
But it gives compile error: Variable does not exist: q.opportunityid at line 59 column 41
the code is not bulkified, is it the case that you won't bulk insert the records?
and for error, change your code to:
Hi,Rahul
Thans for reply it also give compiler error:Compile Error: Variable does not exist: q.opportunityid at line 57 column 72
at select id,amount from opportunity where id=:q.opportunityid
Change the line of code to
for(Opportunity opp : [select id,amount from opportunity where id in : mapOppidAmount.KeySet()]