function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
PhoenixRising12PhoenixRising12 

Help with Testing an Apex Trigger Handler Class

I have a Trigger Helper Class which I need a Test Class for. What would be the best way to approach this? 
 
public class DuplicateMergeTriggerHandler {
    
    public static void MergeHandler(Set<Id> leadIds) {
	
        List<String> LeadListEmails = new List<String>();
        List<String> LeadNames = new List<String>();
        List<String> LeadPhones = new List<String>();
        
        List<Lead> myleads = [SELECT Id, Name, Email, Phone FROM Lead WHERE Id IN :leadIds];
        
        for (Lead L1 : myleads) {
           LeadListEmails.add(L1.Email);
        }
		
        for (Lead L2 : myleads){
            LeadNames.add(L2.Name);
        }
        
        for (Lead L3 : myleads){
            
            LeadPhones.add(L3.Phone);
        }

        Map<String,Account> mapAccountsEmail = new Map<String,Account>();
         
        for (Account A : [SELECT Id, PersonEmail FROM Account WHERE PersonEmail IN :LeadListEmails]){    
            mapAccountsEmail.put(A.PersonEmail, A);   
        }
        
        Map<String,Account> mapAccountsName = new Map<String,Account>();
        
        for (Account A1 : [SELECT Id, Name FROM Account WHERE Name IN :LeadNames]){
            
           mapAccountsName.put(A1.Name, A1);
        }
        
       Map<String,Account> mapAccountsPhone = new Map<String,Account>();
        for (Account A2 : [SELECT Id, Phone FROM Account WHERE Phone IN :LeadPhones]){
            
            mapAccountsPhone.put(A2.Phone, A2);
        }
        
        LeadStatus convertStatus = [SELECT Id, MasterLabel FROM Leadstatus WHERE IsConverted = TRUE LIMIT 1];
        
        List<Database.LeadConvert> lstLC = new List<Database.LeadConvert>();
	  
        for (lead MyLead : myleads) {
            
 	        Account matchingAccountEmail = mapAccountsEmail.get(MyLead.Email);
            Account matchingAccountName = mapAccountsName.get(MyLead.Name);
            Account matchingAccountPhone = mapAccountsPhone.get(MyLead.Phone);
	 
            if(matchingAccountEmail != NULL){
         		Database.LeadConvert lc = new database.LeadConvert();
 				lc.setLeadId(MyLead.Id);
                lc.setDoNotCreateOpportunity(TRUE);
         		lc.setAccountId(matchingAccountEmail.Id);
                lc.setConvertedStatus(convertStatus.MasterLabel);
                lstLc.add(lc);
            } else if (matchingAccountName != NULL){
                Database.LeadConvert lc1 = new database.LeadConvert();
 				lc1.setLeadId(MyLead.Id);
                lc1.setDoNotCreateOpportunity(TRUE);
         		lc1.setAccountId(matchingAccountName.Id);
                lc1.setConvertedStatus(convertStatus.MasterLabel);
                lstLc.add(lc1);
            }else if (matchingAccountPhone != NULL){
                Database.LeadConvert lc2 = new database.LeadConvert();
 				lc2.setLeadId(MyLead.Id);
                lc2.setDoNotCreateOpportunity(TRUE);
         		lc2.setAccountId(matchingAccountPhone.Id);
                lc2.setConvertedStatus(convertStatus.MasterLabel);
                lstLc.add(lc2);
                
            }        
        }
            
        if(!lstLc.isEmpty()) {
            List<Database.LeadConvertResult> lcr = Database.convertLead(lstLc);
            System.debug(+'result'+lcr); 
            
        } 
            
    }}

 
AnkaiahAnkaiah (Salesforce Developers) 
Hi,

Refer the below link have solution.
https://developer.salesforce.com/forums/?id=906F0000000BLZFIA4

If this helps,Please mark it as best answer.

thanks!!