Tuesday, 5 February 2019

updated batch vwith valid phone

/*     Class Name:InvocaCallLogMatchWithLeadBatch     Developer Name:Krishna Nagendra Rao.Yerru               Created Date:   04-Feb-2019     Test Class Name: InvocaCallLogMatchWithLeadBatch_Test     Project Name: SP-3530:Create Batch Process to match Invoca Call Logs with Leads ------------------------------------------------------------------------------------------------------------------     CH#             Description                             Developer                       Modified Date ------------------------------------------------------------------------------------------------------------------ */ global class InvocaCallLogMatchWithLeadBatch implements Database.Batchable<sobject>{        Public List<String> StatusVal = new List<String> {'New'};     Public String query='SELECT Id,Status__c,INVOCA_FOR_SF__calling_phone_number__c,INVOCA_FOR_SF__advertiser_campaign_name__c,INVOCA_FOR_SF__Lead__c, INVOCA_FOR_SF__Lead__r.Phone FROM INVOCA_FOR_SF__Invoca_Call_Log__c where INVOCA_FOR_SF__calling_phone_number__c!=null and Status__c in:StatusVal';       global Database.Querylocator start(Database.BatchableContext BC){         return Database.getQueryLocator(query);     }       global void execute(Database.BatchableContext BC,  List<INVOCA_FOR_SF__Invoca_Call_Log__c> invocaLeadMatch){          List<ID> leadinCalllogs = new List<ID>();         Map<INVOCA_FOR_SF__Invoca_Call_Log__c,String> leadCalllogsMap = new Map<INVOCA_FOR_SF__Invoca_Call_Log__c,String>();         List<ID> leadCalllogs = new List<ID>();         list<ID> LeadupdStatusIDS= new list<ID>();         boolean LeadFound=false;         List<INVOCA_FOR_SF__Invoca_Call_Log__c> UpdCalllogLeads=New List<INVOCA_FOR_SF__Invoca_Call_Log__c>();         List<INVOCA_FOR_SF__Invoca_Call_Log__c> UpdNOLeadlogs=New List<INVOCA_FOR_SF__Invoca_Call_Log__c>();         list<ID> updcalllogids= new list<ID>();                  if(invocaLeadMatch!= null){                 for(INVOCA_FOR_SF__Invoca_Call_Log__c invoca: invocaLeadMatch){                     leadinCalllogs.add(invoca.id);                     leadCalllogsMap.put(invoca,invoca.INVOCA_FOR_SF__calling_phone_number__c);                   }                                if(leadCalllogsMap.size()>0){                     List<Lead> LeadMatches=[Select id,Phone,(SELECT Id,CampaignID,Campaign.name,LeadId FROM CampaignMembers) from Lead where Phone in:leadCalllogsMap.Values()];                     System.debug('LeadMatches is'+LeadMatches);                      for(INVOCA_FOR_SF__Invoca_Call_Log__c calllog:leadCalllogsMap.Keyset()){                         boolean flagval=false;                        for(Lead le:LeadMatches){                             if(le.CampaignMembers.size()>0){                                 CampaignMember Campname=le.CampaignMembers[0];                                 String CampnameIs=Campname.Campaign.name;                                 String LeadPhone=le.Phone;                                 String ValLeadPhone=validatephone(LeadPhone);                                 String CalllogPhone=calllog.INVOCA_FOR_SF__calling_phone_number__c;                                 String VallogPhone=validatephone(CalllogPhone);                                 System.debug('Lead is'+le);                                 System.debug('Call log is'+calllog);                                 System.debug('CampnameIs on Lead'+CampnameIs +'CampnameIs on calllog'+calllog.INVOCA_FOR_SF__advertiser_campaign_name__c);                                 System.debug('Phone on Lead'+le.Phone +'CallerID on calllog'+calllog.INVOCA_FOR_SF__calling_phone_number__c);                                 if(calllog.INVOCA_FOR_SF__advertiser_campaign_name__c==CampnameIs && ValLeadPhone==VallogPhone){                                     System.debug('matched Calllog is'+calllog);                                     System.debug('matched Lead is'+le);                                         if(!LeadupdStatusIDS.contains(le.Id)|| calllog.Status__c!='Matched' ){                                             if(calllog.INVOCA_FOR_SF__Lead__c==null){                                                 System.debug('machedSection***1');                                                 calllog.INVOCA_FOR_SF__Lead__c=le.id;                                                 calllog.Status__c='Matched';                                                 LeadupdStatusIDS.add(le.id);                                                 LeadFound= true;                                                 flagval=true;                                                                                            }                                             else if(flagval==false && calllog.INVOCA_FOR_SF__Lead__c!=null && calllog.Status__c=='New'){                                                 System.debug('machedSection***2');                                                 calllog.Status__c='Matched';                                                 LeadupdStatusIDS.add(le.id);                                                 LeadFound= true;                                                                                              }                                         }                                          //else if(LeadupdStatusIDS.contains(le.Id)){                                             else if(calllog.Status__c!='New'){                                             System.debug('Multiple Record Matches');                                             calllog.Status__c='Multiple Record Matches';                                             LeadFound= true;                                                                                 }                                 }                                 else if(!LeadupdStatusIDS.contains(le.Id) || LeadFound==false){                                     System.debug('calllog with No match Lead are'+calllog);                                     calllog.Status__c='No Match Found';                                     System.debug('calllog with No match Lead are updated'+calllog);                                     LeadupdStatusIDS.add(le.id);                                     LeadFound= true;                                                                      }                              }                         }                         UpdCalllogLeads.add(calllog);                         updcalllogids.add(calllog.id);                     }                            }                            }                                            try{                 if(UpdCalllogLeads!=null && UpdCalllogLeads.size()>0){                         Database.SaveResult [] UpdCalllogLeadsreslts = Database.update(UpdCalllogLeads, false);                         List<INVOCA_FOR_SF__Invoca_Call_Log__c> NoleadMatches=[SELECT Id,Status__c,                         INVOCA_FOR_SF__calling_phone_number__c from INVOCA_FOR_SF__Invoca_Call_Log__c where id in:leadinCalllogs];                         System.debug('NoleadMatches are'+NoleadMatches);                         for(INVOCA_FOR_SF__Invoca_Call_Log__c noleadlogs:NoleadMatches){                             if(noleadlogs.Status__c=='New'){                                 noleadlogs.Status__c='No Match Found';                                 UpdNOLeadlogs.add(noleadlogs);                                                   }                         if(UpdNOLeadlogs!=null && UpdNOLeadlogs.size()>0){                             Database.SaveResult [] UpdNOLeadlogsrecs = Database.update(UpdNOLeadlogs, false);                         }                                                  }                     }                 }                      catch(exception e){                 System.debug('There is problem in updating matching Call log record associated lead records.'+e);             }                      }          global void finish(Database.BatchableContext BC){     }  public String validatephone(String Phoneis) {                String phone=Phoneis;             String Updphone;             if(phone.contains(' ')||phone.contains('-')|| phone.contains('(') || phone.contains(')')){                              if(phone.contains('-')){                     String Updphone1=phone.replace('-','');                     Updphone=Updphone1;                     System.debug('Updated Phone is1 '+Updphone);                 }                 if(Updphone.contains('(')){                     String Updphone2=Updphone.replace('(','');                     Updphone=Updphone2;                     System.debug('Updated Phone is 2'+Updphone);                 }                 if(Updphone.contains(')')){                     String Updphone3=Updphone.replace(')','');                     Updphone=Updphone3;                     System.debug('Updated Phone is3 '+Updphone);                 }                 if(Updphone.contains(' ')){                     String Updphone4=Updphone.replace(' ','');                     Updphone=Updphone4;                     System.debug('Updated Phone is4 '+Updphone);                 }                 System.debug('Updated Phone is '+Updphone);             }         return  Updphone;  } }

1 comment:

  1. Harrah's Philadelphia Casino - Mapyro
    Harrah's Philadelphia Casino. 777 Harrah's Blvd, Chester, PA 고양 출장샵 18702. Directions 세종특별자치 출장안마 · (484) 388-7646. Call Now · More Info. Hours, Accepts Credit 전라남도 출장샵 Cards,  Rating: 2.5 · ‎56 reviews · ‎Price range: $$$Does Harrah's Philadelphia Casino have 서울특별 출장샵 a pool?How is 울산광역 출장샵 Harrah's Philadelphia Casino rated?

    ReplyDelete