+ Start a Discussion
ALAL 

How can I sync Quote Line Items with Opportunity Line Items

Hello, I've created a matching field on the opportunity line item and quote line item objects. When updating the opportunity line item field, I would like the corresponding field on the quote line item to be updated, and vice versa.

When I update the quote line item field, the correspodning field is updated successfully, but when I update the opportunity line item field, the quote line item isn't being updated. Is there something wrong with my opportunity line item trigger? Thank 

Opportunity Line Item Trigger
 
trigger OppSyncPartnerRevShare on OpportunityLineItem (before insert, before update) {
    
   Decimal v2PartnerRev;
    //string vOptyId;
    string vPricebookEntryId;
    string vQuoteId;
    List<QuoteLineItem> qli = new List<QuoteLineItem>([select Id from QuoteLineItem where (QuoteId = :vQuoteId and PricebookEntryId = :vPricebookEntryId)]);
 
    for(OpportunityLineItem oppLine : Trigger.new){
    
        v2PartnerRev = oppLine.X2Partner_Rev_Share_Value__c;
        //vOptyId = oppLine.OpportunityId;
        vPricebookEntryId = oppLine.PricebookEntryId;
        vQuoteId = oppLine.Quote_ID__c;
    }
    for(QuoteLineItem quoteLine : qli){
        
        quoteLine.X2Partner_Rev_Share_Value__c = v2PartnerRev;
    //    qli.add(quoteLine);
     //   update(quoteLine);
    }
  //  update qli;
   
    

}


Quote Line Item Trigger 
 
trigger updateQuoteLineItemPartnerRevShare on QuoteLineItem (before insert, before update) {
    
    Decimal v2PartnerRevShare;
    string vOptyId;
    string vPricebookEntryId;
    string vQuote;
 
    for(QuoteLineItem quoteLine : Trigger.new){
         Quote q = new Quote();
        String oppId = q.OpportunityId;
        vOptyId = oppId;
        vPricebookEntryId = quoteLine.PricebookEntryId;
        
        for(OpportunityLineItem oppLine : [select Id, X2Partner_Rev_Share_Value__c from OpportunityLineItem where (OpportunityId = :vOptyId and PricebookEntryId = :vPricebookEntryId)]){
            v2PartnerRevShare = oppLine.X2Partner_Rev_Share_Value__c;
            //oppLine.
        }
        
   //     quoteLine.X2Partner_Rev_Share_Value__c = v2PartnerRevShare;
   
    }

}