Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void syncronizeQLI(list <QuoteLineItem> lstQLI){
- map<string,string> mapQuoteOppty=new map<string,string>();
- string JSONContent=Json.Serialize(lstQLI);
- System.debug('##### JSONCONTENT '+JSONContent);
- JSONParser parser =JSON.createParser(JSONContent);
- list<string> OpptyLineId=new list<string>();
- list<string> QuoteLineId=new list<string>();
- System.debug('parser-------->'+parser );
- while (parser.nextToken() != null)
- {
- if(parser.getCurrentToken()==JSONToken.VALUE_STRING && parser.getCurrentName()=='OpportunityLineItemId__c')
- OpptyLineId.add(parser.getText());
- if(parser.getCurrentToken()==JSONToken.VALUE_STRING && parser.getCurrentName()=='Id')
- QuoteLineId.add(parser.getText());
- parser.nextToken();
- if(parser.getCurrentToken()==JSONToken.VALUE_STRING && parser.getCurrentName()=='OpportunityLineItemId__c')
- OpptyLineId.add(parser.getText());
- if(parser.getCurrentToken()==JSONToken.VALUE_STRING && parser.getCurrentName()=='Id')
- QuoteLineId.add(parser.getText());
- }
- System.debug('OpptyLineId-------->'+OpptyLineId);
- System.debug('QuoteLineId-------->'+QuoteLineId);
- integer iCount=0;
- for(string strOppLineId : OpptyLineId)
- {
- string iQuoteLineId=QuoteLineId[iCount];
- mapQuoteOppty.put(iQuoteLineId,strOppLineId);
- iCount++;
- }
- System.debug('************ MAP QUOTE OPP '+mapQuoteOppty);
- Set<Id> SetOppId=new Set<Id>();
- Set<Id> SetQuoteId=new Set<Id>();
- for(QuoteLineItem QLI : lstQLI)
- {
- SetQuoteId.add(QLI.QuoteId);
- }
- List<Quote> Lstquotes =[SELECT id, OpportunityId, isSyncing FROM Quote WHERE isSyncing = true AND Id in :SetQuoteId];
- for(Quote Qt:Lstquotes)
- {
- SetOppId.add(Qt.OpportunityId);
- }
- List<OpportunityLineItem> lstOLI=[select Id, OpportunityId,Field1__c,Field2__c from OpportunityLineItem where OpportunityId in:SetOppId];
- Map<Id,OpportunityLineItem> MapOLI=new Map<Id,OpportunityLineItem>([select Id,OpportunityId, Field2__c, Field1__c from OpportunityLineItem where OpportunityId in:SetOppId]);
- Map<Id,QuoteLineItem > MapQLI=new map<Id,QuoteLineItem>([Select Id,QuoteId, Field2__c, Field1__c from QuoteLineItem where QuoteId in:SetQuoteId]);
- list<OpportunityLineItem> updateQuoteLineItem =new list<OpportunityLineItem >();
- for(QuoteLineItem qli:MapQLI.values())
- {
- system.debug(' -------- QLI.ID '+qli.id);
- system.debug('mapQuoteOppty.get(qli.id) '+mapQuoteOppty.get(qli.id));
- if(mapQuoteOppty.get(qli.id)!=null)
- {
- String OppID = mapQuoteOppty.get(qli.id);
- System.debug('###### OPPID ----------- '+OppID);
- OpportunityLineItem OLI = MapOLI.get(OppID);
- qli.Field1__c=OLI.Field2__c;
- qli.Field2__c=OLI.Field1__c;
- updateQuoteLineItem.add(OLI);
- }
- }
- system.debug('UPDATES QUOTE LINE ITEM LIST '+updateQuoteLineItem);
- update updateQuoteLineItem;
- }
- trigger QuoteLineItemAfterInsert on QuoteLineItem (before insert, after insert){
- list<QuoteLineItem> lstQLI = new list <QuoteLineItem>();
- for ( QuoteLineItem qli : trigger.new){
- lstQLI.add(qli);
- }
- system.debug('LIST QLI TRIGGER '+ lstQLI);
- if(lstQLI.size()>0){
- AP001_SyncronazingQLI_OLI.syncronizeQLI(lstQLI);
- }
- }
- while (parser.nextToken() != null)
- {
- if(parser.getCurrentToken()==JSONToken.VALUE_STRING && parser.getCurrentName()=='OpportunityLineItemId__c')
- OpptyLineId.add(parser.getText());
- if(parser.getCurrentToken()==JSONToken.VALUE_STRING && parser.getCurrentName()=='Id')
- QuoteLineId.add(parser.getText());
- parser.nextToken();
- if(parser.getCurrentToken()==JSONToken.VALUE_STRING && parser.getCurrentName()=='OpportunityLineItemId__c')
- OpptyLineId.add(parser.getText());
- if(parser.getCurrentToken()==JSONToken.VALUE_STRING && parser.getCurrentName()=='Id')
- QuoteLineId.add(parser.getText());
- }
- for (QuoteLineItem qli : lstQLI) {
- OpptyLineId.add(qli.OpportunityLineItemId__c);
- QuoteLineId.add(qli.Id);
- }
- SELECT Id, OpportunityLineItemId FROM QuoteLineItem WHERE QuoteId ='0Q01N00000xxxxxxx' AND OpportunityLineItemId != null
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement