function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Subhani PSubhani P 

Verify Contact Email address. If Email is not present send an email to login user

I am looking for a specific requirement where I need to send an email login user whenever the user is creating a new Contact in Salesforce. If any contact exist with the same email Id, I need to send an email to login user and do not allow to create the contact.
I tried with a before insert trigger by searching in stack exchange and it allows me not to insert a new record with different email id.
I need help on how to sent a particular email template notification to login user with the details that I am entering while creation of Contact record.
Ex: If My contact details like,
Name: Smith Email: smith.k@gmail.com
Email should go as,
Hi Smith,
Below Email is does not exist in Contact records
Email: smith.k@gmail.com
Below is my code trigger.
trigger triggerOnContact on Contact (before insert) { final String errMsg = 'The Email is Not available in the Contacts '; Set< String > emailSet = new Set< String >(); for( Contact c : Trigger.new ) emailSet.add( c.Email ); Map< String, Id > duplicateContactMap = new Map< String, Id >(); for( Contact c : [select Id, Email from Contact where Email = :emailSet] ) duplicateContactMap.put( c.Email, c.Id ); for( Contact c : Trigger.new ){ if(!duplicateContactMap.containsKey(c.Email)){ c.addError( errMsg); } } }
Please help me how to implement the requested logic.. Thanks in advance