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
sushma76sushma76 

Copy Fields from OpportunityProduct to QuoteLineItem

When a Quote is created from an Opporutnity , all the product line items gets copied over, including some standard fields like

 

Line Item Description

Quantity

Sales Price.

 

There is a COST field on OpportunityProduct, which also needs to get copied over to the Quote LIne Items.

 

I cannot do this using Formulas or WF Rule.

 

I think, Trigger can be done here.

 

Can some one please confirm this and guide me to right direction. ?

 

 

Thanks

sumita

 

 

 

ForceLoverForceLover

Hi Sumita

 

It will give you a quick start ,

 

trigger trgr_oppquoteliupdate on OpportunityLineItem (after insert,after update) {
      
   Set<Id> SetprodIdsoli=new Set<Id>();
   List<QuoteLineItem> updateQli=new List<QuoteLineItem>();
  
   if(trigger.isafter){
     
      for(OpportunityLineItem OLI:trigger.new){
         
          SetprodIdsoli.add(OLI.PricebookEntryId);
          System.debug('set of opp product ids'+SetprodIdsoli);
      }
      List<QuoteLineItem> lstqli=[select PricebookEntryId,Quantity from QuoteLineItem where PricebookEntryId IN:SetprodIdsoli];     
  
   if(lstqli!=Null || lstqli.size()>0){
     
      for(OpportunityLineItem OLI:trigger.new){
         
          for(QuoteLineItem Ql:lstqli){
         
              if(OLI.PricebookEntryId==Ql.PricebookEntryId){
                  Ql.Quantity =OLI.Quantity;
                  updateQli.add(Ql);                
              }
         
          }     
      }

   }
   }
   if(updateQli!=Null || updateQli.size()>0){
      update updateQli;
   }
}

 

Please accept it as solution if it solves your requirement.. feel free to ask.. 

sunayasunaya

this helped. thanks.