Create a field 'Search result' on Lead.When lead is updated then check if the email of lead is matching with any contact.If matching set the field as 'Exact match' or else 'No Match'
trigger FindDupes on Lead (before insert, before update) { for(Lead myLead:Trigger.new) { if(myLead.Email!=null) { List<Contact> dupes=[Select Id from Contact where Email =:myLead.Email];
if(dupes.size()>0) { //Assigning the value for Search Result for the if part myLead.Search_result__c='Exact match';
} else { //Assigning the value for Search Result for the else part myLead.Search_result__c='No match'; } }
Try this code,
trigger FindDupes on Lead (before insert, before update)
{
for(Lead myLead:Trigger.new)
{
if(myLead.Email!=null)
{
List<Contact> dupes=[Select Id from Contact where Email =:myLead.Email];
if(dupes.size()>0)
{
//Assigning the value for Search Result for the if part
myLead.Search_result__c='Exact match';
}
else
{
//Assigning the value for Search Result for the else part
myLead.Search_result__c='No match';
}
}
}
}
This code will fulfill your requirement --
If found this helpful mark it as best so that it helps others in solving the same.
Thanks
Akshay
Please find the bulkified version of code ..