Check Duplicate EmailId when user Insert the Contact
Check Duplicate EmailId when user Insert the Contact trigger OnContactChekDuplicateEmail on Contact (before insert) { Set<String> emails = new Set<String>(); List<Contact>lstCon = new List<Contact>(); set<String> setEmail = new set<String>(); for(Contact Con:trigger.new){ emails.add(con.Email); } lstCon=[Select name,id, email from Contact where Email in:emails]; for(Contact con :lstCon){ setEmail.add(con.email); } for(Contact c :trigger.new){ if(setEmail.contains(c.email)){ c.adderror('Email duplicate'); } } }