You need to sign in to do that
Don't have an account?
Hermann Ouré
Thanks
Trigger Contact Duplicates
Hello,
I am trying to write a trigger to stop user creating contact with the same email address. But I keep getting an error
System.NullPointerException: Attempt to de-reference a null object
on line 8 for:
conMap.get(c.Id).EmailHow can I fix this error
Thanks
trigger ContactDuplicate on Contact (before insert) { Map<Id, Contact> conMap = new Map<Id, Contact>([SELECT Id, Email FROM Contact WHERE Email != null]); System.debug('Map ' +conMap); if(Trigger.isBefore && Trigger.isInsert) { for(Contact c : Trigger.New) { if(c.Email != null && c.Email == conMap.get(c.Id).Email) { c.Email.addError('Duplicate Contact'); } } } }
Try Below Code Pleae Mark It As Best Answer If It Helps
Thank You!