2 answers
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
if you need any assistanse, Please let me know!!Kindly mark my solution as the best answer if it helps you.ThanksMukeshpublic 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 !!!');
}
}
}
}