trigger PreventDuplicateContacts on Contact (before insert) {
Set <String> emailSet = new Set<String>();
for (contact con:trigger.new) {
if(Con.Email != null){
emailSet.add(con.Email);
}
}
List <Contact> contactList = [SELECT Email,Phone FROM Contact WHERE email IN :emailSet];
for (contact con:trigger.new) {
If (contactList.size() > 0) {
con.Email.adderror( 'Duplicate Contact Found. Use Existing Contact.' );
}
}
}
Please Mark It As Best Answer If It Helps Thank You!
Try Below Trigger Example Please Mark It As Best Answer If It Helps
Thank You!
Hi Krutik,
It is not possible to achieve this by configuration i.e., by writing the validation rule. So you need to write the Code i.e, trigger.
Regards,
Priya Ranjan
Salesforce Support