Skip to main content
can any one please help me in this code. I am having a error.

Trigger :

trigger Trg_CheckLeadEmail on Lead (before insert,before update) {  

if(trigger.isBefore  && trigger.isInsert || Trigger.isUpdate))

{

    Trg_ClassCheckLeadEmail.CheckEmail(Trigger.new,Trigger.oldMap);

  }

}

Class:

public class Trg_ClassCheckLeadEmail {

 public static void CheckEmail ( List<Lead> newLeadList, map<String, Contact> OldMapContacts){

    

    // List<Lead> newLeadList= new list<Lead>();

    map<String,Contact>  ContMapSet = new map<String, Contact>();

    list<Contact> conlst = [SELECT Id, Email FROM Contact];

    

    for (Contact cont:conlst) {

        ContMapSet.put(cont.Email, cont);

    } 

    for(lead led : newLeadList) 

    {

        if((led.Email != null) && (trigger.isInsert || (led.Email != OldMapContacts.get(led.id).Email))) 

        {

            if(ContMapSet.containsKey(led.Email))

            {

                led.Email.addError('Email Already Exists !!!');

            }

        }               

       }

    }

}

Error: Compile Error: Method does not exist or incorrect signature: void CheckEmail(List<Lead>, Map<Id,Lead>) from the type Trg_ClassCheckLeadEmail at line 7 column 29
2 answers
  1. Aug 1, 2022, 7:51 AM
    Hi Nazil,

    Please use below code:-

    Trg_CheckLeadEmail

    trigger Trg_CheckLeadEmail on Lead (before insert,before update) {

    if(trigger.isBefore && trigger.isInsert || Trigger.isUpdate))

    {

    Trg_ClassCheckLeadEmail.CheckEmail(Trigger.new);

    }

    }

    Trg_ClassCheckLeadEmail

    public class Trg_ClassCheckLeadEmail {

    public static void CheckEmail ( List<Lead> newLeadList){

    Set<Id> conIds = new Set<Id>();

    for(Lead l : newLeadList)

    {

    conIds.add(l.WhoId);

    }

    Map<Id,Contact> mapConlst = New Map<Id,Contact>([SELECT Id, Email FROM Contact where Id IN: conIds]);

    for(Lead l : newLeadList){

    if(mapConlst.get(l.whoId).Email == l.email){

    l.Email.addError('Email Already Exists !!!');

    }

    }

    }

    }

    if you need any assistanse, Please let me know!!

    Kindly mark my solution as the best answer if it helps you.

    Thanks

    Mukesh

     
0/9000