function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
kishore goud 3kishore goud 3 

Update opportunity based on quote line item

Hi ,
Currently,I am working on below scenario.When check box in quote line Item object is checked ,corresponding check box in opportunity should be checked. Can anyone please post the  trigger code for this scenario
Best Answer chosen by kishore goud 3
Prashant Pandey07Prashant Pandey07
Hi Kishore,

You may check the below code and let me know if this works for you..

Note- We can still optimize this code for better performance let me know if that is needed.
 
trigger updateQuotelineitem on QuoteLineItem (after insert, after update) {

set<id> ids=trigger.newmap.keyset();
set<id>idss=new set<id>();
for(QuoteLineItem qol:trigger.new){

idss.add(qol.Quoteid);

}

List<opportunity> mapofop=new list<opportunity>();

set<id> idq=new set<id>();

map<id,Quote> mapofquote=new map<id,Quote>([select id,opportunityid from Quote where id=:idss]);

for(Quote qa:mapofquote.values()){
idq.add(qa.opportunityid);
}

list<opportunity> listop=[select id from opportunity where id=:idq];

map<id,QuoteLineItem> mapq=new map<id,QuoteLineItem>([select id,Test__c,HasSchedule,Quoteid from QuoteLineItem where id=:ids]);
 

    for(QuoteLineItem ql: mapq.Values()){

      if(ql.lineitemcheckbox__c==true){
          for(opportunity op:listop){

            op.checkbox__c=true;
            mapofop.add(op);
        }
   
    }


}
if(mapofop.size()>0)
update mapofop;

}

--
Thanks,
Prashant

All Answers

Prashant Pandey07Prashant Pandey07
Hi Kishore,

You may check the below code and let me know if this works for you..

Note- We can still optimize this code for better performance let me know if that is needed.
 
trigger updateQuotelineitem on QuoteLineItem (after insert, after update) {

set<id> ids=trigger.newmap.keyset();
set<id>idss=new set<id>();
for(QuoteLineItem qol:trigger.new){

idss.add(qol.Quoteid);

}

List<opportunity> mapofop=new list<opportunity>();

set<id> idq=new set<id>();

map<id,Quote> mapofquote=new map<id,Quote>([select id,opportunityid from Quote where id=:idss]);

for(Quote qa:mapofquote.values()){
idq.add(qa.opportunityid);
}

list<opportunity> listop=[select id from opportunity where id=:idq];

map<id,QuoteLineItem> mapq=new map<id,QuoteLineItem>([select id,Test__c,HasSchedule,Quoteid from QuoteLineItem where id=:ids]);
 

    for(QuoteLineItem ql: mapq.Values()){

      if(ql.lineitemcheckbox__c==true){
          for(opportunity op:listop){

            op.checkbox__c=true;
            mapofop.add(op);
        }
   
    }


}
if(mapofop.size()>0)
update mapofop;

}

--
Thanks,
Prashant
This was selected as the best answer
kishore goud 3kishore goud 3
Thanks for posting the code.