You need to sign in to do that
Don't have an account?
sona gaikwad
how to write test class for this method ---urgent
public static Boolean LeadDuplicateCheck(String contactInfo){ String searchQuery= 'FIND \'' + contactInfo.trim() + '*\' IN ALL FIELDS RETURNING Lead(Id,MobilePhone,Mobile_2__c,Whats_App_Number__c,LandLine__c,Email), Account(Id,PersonMobilePhone,Mobile_2__c,Whats_App_Number__c,LandLine__c,PersonEmail)'; List<List <sObject>> searchList= search.query(searchQuery); Lead [] leads= ((List<Lead>)searchList[0]); Account [] accounts = ((List<Account>)searchList[1]); if(leads.size()>0) { /* this line is not covered */ for(Lead lead:leads ){ if((lead.MobilePhone!=null && contactInfo.contains(lead.MobilePhone))||(lead.Mobile_2__c!=null && contactInfo.contains(lead.Mobile_2__c))||(lead.Whats_App_Number__c!=null &&contactInfo.contains(lead.Whats_App_Number__c))|| (lead.LandLine__c!=null && contactInfo.contains(lead.LandLine__c))||(lead.Email!=null && contactInfo.contains(lead.Email))) return true; //duplicate return true } /* this line is not covered */ } if(accounts.size()>0) { /* this line is not covered */ for(Account account:accounts ){ if((account.PersonMobilePhone!=null && contactInfo.contains(account.PersonMobilePhone))||(account.Mobile_2__c!=null && contactInfo.contains(account.Mobile_2__c))|| (account.Whats_App_Number__c!=null &&contactInfo.contains(account.Whats_App_Number__c))|| (account.LandLine__c!=null && contactInfo.contains(account.LandLine__c))||(account.PersonEmail!=null && contactInfo.contains(account.PersonEmail))) return true; //duplicate return true } /* this line is not covered */ } return false; } **test class** @isTest public with sharing class checkleaddetails { public static testMethod Boolean checkleadinfo () { Account c = new Account(); { RecordType personAccountRecordTypeId = [select developerName from RecordType where IsPersonType=True And DeveloperName = 'personAccount']; c.RecordtypeId = personAccountRecordTypeId.Id; c.PersonMobilePhone='9743800309'; c.LastName='Jitesh'; c.FirstName='kape'; c.Date_of_Birth__c = date.today()-2; c.Mobile_2__c='9743800309'; c.Whats_App_Number__c = '8652146259'; c.LandLine__c ='022-25412365'; c.PersonEmail = 'email@gmail.com'; insert c; } Lead leadobj=new Lead( FirstName=c.id, LastName = c.id, MobilePhone = c.id, Mobile_2__c= c.id, Whats_App_Number__c= c.Whats_App_Number__c, LandLine__c= c.LandLine__c, Email= c.PersonEmail); insert leadobj ; Test.StartTest(); LeadHandlerClass.LeadDuplicateCheck(leadobj.MobilePhone); LeadHandlerClass.LeadDuplicateCheck(leadobj.Mobile_2__c); LeadHandlerClass.LeadDuplicateCheck(leadobj.Whats_App_Number__c); LeadHandlerClass.LeadDuplicateCheck(leadobj.LandLine__c); LeadHandlerClass.LeadDuplicateCheck(leadobj.Email); LeadHandlerClass.CCHelp(); Test.StopTest(); return false ; } }
All Answers