How to check for duplicate Leads if a Contact already exist with the same Email ?
Hello folks, in this post you will learn to create a trigger on Lead to check for duplicate records if a Contact is already exist with same email address.
Please follow below code :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | trigger CheckDuplicateLeads on Lead (before insert, before update) {
for (Lead myLead : Trigger.new) {
//Check if the email is not null
if (myLead.Email != null) {
//Get list of contact with the same email we have used in Lead
List<Contact> con = [SELECT Id FROM Contact WHERE Email = :myLead.Email];
//Check if the list is not empty
if (con.size() > 0) {
//Action if duplicate
} else {
//Action if Unique
}
}
}
}
|
Please check below links also and subscribe if you like the content :
- How to get Parent Id from encoded URL in Lightning Component ?
- How to add sorting in Lightning Data Table ?
- How to Send SMS from Salesforce ?
- How to Add Star Ratings in Salesforce ?
If you have any question please leave a comment below.
If you would like to add something to this post please leave a comment below.
Share this blog with your friends if you find it helpful somehow !
Thanks
Keep Coding 😊


2 Comments
nice! thank you:)
ReplyDeleteYou’re welcome 😇
Delete