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
Swaroopa Akula 2Swaroopa Akula 2 

Need Test class for auto populate account on lead when the email domain match

Here is the code for auto populate account on lead when the email domain match. Can pls someone let me know test class for this class

public static void handleBeforUpdate() 
    {
        Set<String> leadEmails = new Set<String>();
        Map<String,Id> conmap = new Map<String,Id>();
        List<Lead> vLstLead = new List<Lead>();

    for(Lead l :(List<Lead>)trigger.new){

        if(!l.IsConverted && null != l.email && '' != l.email)
            leadEmails.add(l.Lead_s_email_domain__c);
    }

    Set<String> contactEmailMatches = new Set<String>();
    
    List<Contact> conList = [SELECT Id,Accountid,Email,Contact_s_email_domain__c From Contact where Contact_s_email_domain__c IN :leadEmails];
   
    if(conList != null) {
    for(Contact c : conList) {
        contactEmailMatches.add(c.Contact_s_email_domain__c);
        conmap.put(c.Contact_s_email_domain__c, c.accountId);
       }
    }
  

    for(Lead l :(List<Lead>)trigger.new){

        if(!l.IsConverted){
         if(contactEmailMatches.contains(l.Lead_s_email_domain__c) && !l.is_domain_matched__c){
                l.is_domain_matched__c = True;
                l.AccountName__c = conmap.get(l.Lead_s_email_domain__c);
             }
            }
        }
    }

}