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!