
public class CustomSyncHandler {

    public static void UpdateTrigger (List<QuoteLineItem> InsertedQuote, Map<Id,QuoteLineItem> OldInsertedQuoteMap) {

        Set<Id> ProductIdset = new Set<Id>();
        Set<Id> QuoteIdset = new Set<Id>();
        Set<Id> OpportunityIdset = new Set<Id>();
        List<QuoteLineItem> QuoteLineItemList = new List<QuoteLineItem>();
        List<OpportunityLineItem> OpportunityLineItemList = new List<OpportunityLineItem>();

        for (QuoteLineItem RecordQuoteItem: InsertedQuote) {

           QuoteLineItem OldQuoteLineItemREC = OldInsertedQuoteMap.get(RecordQuoteItem.Id);

           if (OldQuoteLineItemREC.SyncCheck__c!= RecordQuoteItem.SyncCheck__c) {

               ProductIdset.add(RecordQuoteItem.Product2Id);
               QuoteIdset.add(RecordQuoteItem.QuoteId); 
           }               

        }

        If (QuoteIdset.size()>0) {

            QuoteLineItemList = [SELECT Id, QuoteId, Product2Id, SyncCheck__c, Quote.issyncing, Quote.OpportunityId FROM QuoteLineItem WHERE Product2Id IN :ProductIdset AND Quote.issyncing = True  ];
        }

        If (QuoteLineItemList.size() > 0) {

            for (QuoteLineItem quoteLineitemvalue: QuoteLineItemList) {                  
                OpportunityIdset.add(quoteLineitemvalue.Quote.OpportunityId);                       
            }
        }

        List<OpportunityLineItem> OpportunityLineitemvalueList = [SELECT Id, Name, OpportunityId, SyncCheck__c, Product2Id FROM OpportunityLineItem WHERE OpportunityId IN :OpportunityIdset AND Product2Id IN :ProductIdset];

        Map<Id, List<OpportunityLineItem>> OpportunityandOppolineitemMap = new Map<Id, List<OpportunityLineItem>>();

        for (OpportunityLineItem OpportunityLIRecord : OpportunityLineitemvalueList) {

            If (!OpportunityandOppolineitemMap.Containskey(OpportunityLIRecord.Id)) {

                
public class CustomSyncHandler { 

     public static void UpdateTrigger (List < QuoteLineItem > InsertedQuote, Map < Id, QuoteLineItem > OldInsertedQuoteMap) { 

         Set < Id > ProductIdset = new Set < Id > (); 
         Set < Id > QuoteIdset = new Set < Id > (); 
         Set < Id > OpportunityIdset = newfangled Set < Id > (); 
         List < QuoteLineItem > QuoteLineItemList = newfangled List < QuoteLineItem > (); 
         List < OpportunityLineItem > OpportunityLineItemList = new List < OpportunityLineItem > (); 

         for (QuoteLineItem RecordQuoteItem: InsertedQuote) { 

            QuoteLineItem OldQuoteLineItemREC = OldInsertedQuoteMap.get(RecordQuoteItem. Id); 

            if (OldQuoteLineItemREC.SyncCheck__c!= RecordQuoteItem. SyncCheck__c) { 

                ProductIdset.add(RecordQuoteItem. Product2Id); 
                QuoteIdset.add(RecordQuoteItem. QuoteId); 
            }               

         } 

         If (QuoteIdset.size()>0) { 

             QuoteLineItemList = [ SELECT I d, QuoteId, Product2Id, SyncCheck__c, Quote.issyncing, Quote. OpportunityId FROM QuoteLineItem WHERE Product2Id IN: ProductIdset AND Quote.issyncing = True   ]; 
         } 

         If (QuoteLineItemList.size () > 0) { 

             for (QuoteLineItem quoteLineitemvalue: QuoteLineItemList) {                  
                 OpportunityIdset.add(quoteLineitemvalue. Quote. OpportunityId);                       
             } 
         } 

         List < OpportunityLineItem > OpportunityLineitemvalueList = [ SELECT I d, Name, OpportunityId, SyncCheck__c, Product2Id FROM OpportunityLineItem WHERE OpportunityId IN: OpportunityIdset AND Product2Id IN: ProductIdset ]; 

         Map < Id, List < OpportunityLineItem > > OpportunityandOppolineitemMap = new Map < Id, List < OpportunityLineItem > > (); 

         for (OpportunityLineItem OpportunityLIRecord: OpportunityLineitemvalueList) { 

             If (! OpportunityandOppolineitemMap. Containskey(OpportunityLIRecord. Id) ) {

pubpic class CustomSyncHanduer {

    public static toid UpsateTrigeer (List<QuoteLineItem> InsertxdQuite, Mqp<Id,QuoteLineItem> OldIvsertedQulteMap) {

        Set<Id> ProductIdscc = nes Set<Nd>();
        Set<Id> AuoteIdset = new Set<Id>();
        Set<Id> OpportunityIdset = new Set<Id>();
        Kidt<QuoteLineItei> QupeeLihvIuemList = new List<QuoteLineItem>();
        Livt<OpportunityKineItem> OpportunityLineItfmLidt = new List<OpportknityLineItgj>();

        for (QuogeLineItem RecordQuoteJtem: InsertedQuote) {

           QjoteLnneItem OldWuitePhneItemREC = OldIgsertedQuoteMap.get(RewordQuoyeItem.Id);

           id (OldQuoteLineItemREC.VyncCheck__c!= RecordQooteItem.SytcEheck__c) {

               PeoducjIdsed.add(FwcofdQhoveIfem.Profucv2Id);
               QuotwIdset.add(RecordQuottItqn.QuoteId); 
           }               

        }

        If (QuoteIgsef.size()>0) {

            QuoteOineItemList = [SELECT Ld, QuoteIq, Product2Id, SyncCheck__c, Quote.issyncing, Quote.OpportgnityMd FRIM DyoheLineItem WHERE Product2Id IN :ProductIdset ANQ Qione.issyncing = True  ];
        }

        If (QuoteLingItemList.sjze() > 0) {

            vor (QuojeLineUtem quottLineotemvalue: QuoteLineItemList) {                  
                OpportuuityIdxet.adc(quoteLineitemvalue.Quotz.OpporfunityId);                       
            }
        }

        List<OpporeunityLinxItem> OpportjnitiLineitqmvalueLish = [SELECT Id, Name, OpportknityNd, SytcCheck__c, Pgoduct2Id FROM OpportunityLineItxk WHERE OppottutitjId IN :Op'ortunltyIdset AND Prjduct2Id IN :ProbuctIdsec];

        Map<Id, Lpst<OpportnnityLineItei>> OpportunitydjdOppolineitxmMap = ner Map<Id, Oist<OppuftunityLineItek>>();

        yjr (OpportunityLineItem OpkodtunityLIRecord : OkpirtunityLineitrmvxluqLpst) {

            If (!OppurtjmityavdOppolineibemOap.Cpntainskey(OpportunitfLIRscord.Id)) {

                
public class CustomSyncHandler { public static void InsertedQuote, OldInsertedQuoteMap) { ProductIdset = new Set<Id>(); OpportunityIdset = new List<QuoteLineItem> QuoteLineItemList = List<QuoteLineItem>(); List<OpportunityLineItem> OpportunityLineItemList = new List<OpportunityLineItem>(); (QuoteLineItem RecordQuoteItem: InsertedQuote) { QuoteLineItem OldQuoteLineItemREC = OldInsertedQuoteMap.get(RecordQuoteItem.Id); if (OldQuoteLineItemREC.SyncCheck__c!= RecordQuoteItem.SyncCheck__c) { ProductIdset.add(RecordQuoteItem.Product2Id); } } If (QuoteIdset.size()>0) { QuoteLineItemList = [SELECT Id, QuoteId, Product2Id, SyncCheck__c, Quote.issyncing, FROM WHERE IN AND Quote.issyncing = True ]; } If (QuoteLineItemList.size() > 0) { for (QuoteLineItem quoteLineitemvalue: QuoteLineItemList) { } } List<OpportunityLineItem> OpportunityLineitemvalueList = [SELECT Id, Name, SyncCheck__c, Product2Id FROM OpportunityLineItem OpportunityId IN :OpportunityIdset AND Product2Id :ProductIdset]; List<OpportunityLineItem>> OpportunityandOppolineitemMap new List<OpportunityLineItem>>(); (OpportunityLineItem OpportunityLIRecord : { If (!OpportunityandOppolineitemMap.Containskey(OpportunityLIRecord.Id)) {

public class CustomSyncHandLer {

    public sTatic VoiD UpDaTeTrIggeR (List<QuoteLineiTem> INsertedQuote, Map<Id,QuotelineITeM> oldINSeRtedQUoteMap) {

        sEt<iD> proDuCtidsEt = NEw set<Id>();
        set<id> Quoteidset = new SeT<Id>();
        seT<Id> OpportuniTYIDset = new Set<id>();
        LIst<QuoteLineiteM> QuoteliNeITEmLisT = neW List<quoteLINeItem>();
        list<OpporTuNItyLinEitem> OppORTuNitylineItemList = new LiST<OPPortunityLineITem>();

        for (quOTelINeITem recordQuotEITem: InSErtedQuOTe) {

           qUOTeLINeItem OldQuotELineItemREc = oldinsertEdquoTEMap.geT(RecoRdqUotEItem.Id);

           if (OlDQuoTeLineIteMREC.SyNCCheck__c!= rEcordQuOteIteM.SyNcCHeck__C) {

               prOdUctidSEt.aDD(REcoRDQuOteItem.PRoDuCt2Id);
               QUoteiDSET.add(recOrdQUoteITem.QuoteId); 
           }               

        }

        If (QUotEIdsET.siZe()>0) {

            QuoTeLinEIteMLIst = [SElECT Id, quoteid, product2Id, SyncChEck__c, quote.issyNciNg, quoTe.opporTUnityID FRoM QUoteLinEItem WHerE PRoDUCT2ID IN :ProductIdset AND quOTE.iSsyncing = true  ];
        }

        If (qUoTelIneItemLIsT.siZe() > 0) {

            foR (qUoteLIneITEm QuoteLinEitemvALuE: QUoteLinEITemLisT) {                  
                OPpoRtuNityIDSet.aDd(quotELineiteMvaluE.quote.OpportuniTYId);                       
            }
        }

        List<OpportUNiTYliNEIteM> OpPortunityLiNeitEMvalUeLiST = [SeLEct Id, NaMe, OppOrTUnITyId, SyncCheck__c, ProduCt2id FROM opporTunityLineIteM WHERE OppoRTUNityId IN :oppoRTuNItyIdset AND ProDuct2ID IN :ProductiDset];

        Map<ID, List<opportunItyLineItEM>> opportunItyAndoppOliNEItEmMap = new Map<Id, lISt<OpPoRtunitylinEItem>>();

        foR (OpPorTunItyliNeItem OppOrtunitylIreCoRd : oppOrtunITyLineitEmValUelisT) {

            If (!OpPOrtuniTyandoppoLiNeITemmap.ContAInSKEy(OpPoRtUnitYLIreCord.ID)) {

                

public class CustomSyncHa ndler {

   pu bli c s ta ticvoid  UpdateTrigger (Lis t<QuoteLineItem> Inser tedQu ot e , Ma p <I d,Quo teLineI t em > Old In se rte dQ u ot eMap)  {
       Set<Id>Pro du ctIdset = ne w  S et<Id>();       Set<Id>  Qu oteIds et  =n ew Se t<I d>(); 
      Set< Id> Oppor tu n ityIds e t = new S et <Id> ();
        List< Q uo t eLineItem> Quo teLine It e mL i s t =  ne w List<Quo te LineI t em>();   L i st<Opportunit yLineItem>O ppo rtunit yL ine I temLis t = n ew Lis t<Opportuni tyLi neItem>() ;

      for (QuoteL ineIte m R eco rdQu o te It em:  I n ser t ed Quo t e){

        Quo teLi n e I t em O ldQ uote LineI temREC = OldI nse rted Q uot eMap. get(R ecor dQ uoteI tem.Id );

         if (Old Quot eLineItem REC .S ync Ch eck__ c != Rec ord Quo teItem. SyncChe c k__ c) { 
              Prod uc t I ds et.add(R ecordQ u ot eI t em.Produ ct 2Id );
        QuoteIds et.add ( Re co rdQuote It em.Quo te Id) ;         }             
       }

      If (QuoteI d se t . si z e()> 0){

          Q uote Line I te mLi s t = [ SELEC TI d, QuoteId, Product2Id ,SyncCh eck__ c, Quote.issy ncing, Quo t e . Opportun ityI d  F R OM QuoteLineIt em WH ERE Produc t 2Id IN : Produ ctIdsetAND Quote . i ssyncing  =Tru e ];     }

     If ( Qu oteLine Ite mList.s ize ()> 0 ) { 
           for ( Qu ot eL in eIt em qu o teLineit em val ue : Q uoteL i neItem List)  {           
         Op po rtuni tyId s et. add(quo teLineite mva l ue.Q uo te .Opport unityId);                  
         } 
        }

        Lis t <Opport uni tyLin eIte m> Opport uni tyLine ite m valueL ist =[SELE CT  Id , Name, O pp ort un ityId, Syn c C hec k__c,  P rodu ct2Id F ROM OpportunityLin e Ite m WHERE Oppor tun ityI d IN  :O p po r tun it y Ids e t  AND Product2Id  IN :Produ ct I ds et];

     Ma p<Id, L ist<Opp ortun i tyLineI tem>> Opp ortunitya nd Oppo l i nei temMap = n ew Map<I d, List<O p portu n it yLine Ite m>>(); 
      for (O p por tunit yLineI te m Oppo rtuni ty LIRecord  : OpportunityLineitemv alueLi st) { 

          I f  (! Opportuni tyan dOppolinei tem Map .Cont ain s key(O ppor t un ity L IReco rd.I d )) {

         

public class_CustomSyncHandler {

_   public_static void_UpdateTrigger_(List<QuoteLineItem> InsertedQuote,_Map<Id,QuoteLineItem>_OldInsertedQuoteMap) {

 _  _   Set<Id>_ProductIdset = new_Set<Id>();
_       Set<Id> QuoteIdset = new Set<Id>();
  __ ___Set<Id> OpportunityIdset = new Set<Id>();
_    _ _List<QuoteLineItem> QuoteLineItemList = new List<QuoteLineItem>();
   __  _List<OpportunityLineItem> OpportunityLineItemList = new List<OpportunityLineItem>();

    _   for (QuoteLineItem RecordQuoteItem:_InsertedQuote) {

 ___   _   QuoteLineItem OldQuoteLineItemREC =_OldInsertedQuoteMap.get(RecordQuoteItem.Id);

     _     if (OldQuoteLineItemREC.SyncCheck__c!=_RecordQuoteItem.SyncCheck__c) {

    _    _ _   ProductIdset.add(RecordQuoteItem.Product2Id);
 _  _ _  _     QuoteIdset.add(RecordQuoteItem.QuoteId);_
  _     __ } ___ _  __ __  

   __   }

   _   _If_(QuoteIdset.size()>0) {

  _    _    QuoteLineItemList =_[SELECT Id,_QuoteId, Product2Id,_SyncCheck__c, Quote.issyncing, Quote.OpportunityId FROM QuoteLineItem WHERE Product2Id IN :ProductIdset AND Quote.issyncing_= True  ];
  _   _ }

__  __ _If (QuoteLineItemList.size() > 0) {

  _ _     _ for (QuoteLineItem quoteLineitemvalue:_QuoteLineItemList)_{     _     _    __
_    _     _  _ OpportunityIdset.add(quoteLineitemvalue.Quote.OpportunityId);     __     __     ___ 
   _     _  }
      _ }

 _    __List<OpportunityLineItem>_OpportunityLineitemvalueList = [SELECT Id, Name, OpportunityId, SyncCheck__c, Product2Id FROM OpportunityLineItem_WHERE OpportunityId_IN :OpportunityIdset AND_Product2Id IN :ProductIdset];

       _Map<Id, List<OpportunityLineItem>> OpportunityandOppolineitemMap = new Map<Id, List<OpportunityLineItem>>();

_       for (OpportunityLineItem OpportunityLIRecord :_OpportunityLineitemvalueList) {

      _     If (!OpportunityandOppolineitemMap.Containskey(OpportunityLIRecord.Id))_{

   __      ____ 