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
Nithish KrishnasamyNithish Krishnasamy 

there is the email field if one email record is created in that field ,when the same mail is repeated again it should not saved

for example we created email record  named as user123@gmail.com.
the same email record user123@gmail.com is typed for anotheer record it should not beeen saved the error message want to be displayed.
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Nitish,

Do you want a trigger logic for this?

Thanks,
 
Nithish KrishnasamyNithish Krishnasamy
Yes I want trigger
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Nitesh,

Can you try similar to this logic.
 
trigger PreventDuplicateContactEmail on Contact (before insert, before update) {
   Map<String, Contact> contactMap = new Map<String, Contact>();
    for (Contact Contact : Trigger.new) {

        if ((Contact.Email != null) &&
                (Trigger.isInsert ||
                (Contact.Email != 
                    Trigger.oldMap.get(Contact.Id).Email))) {
		

    
            if (contactMap.containsKey(Contact.Email)) {
                Contact.Email.addError('Another new Contact has the '
                                    + 'same email address.');
            } else {
                contactMap.put(Contact.Email, Contact);
            }
       }
    }
	
    
    for (Contact contact : [SELECT Email FROM Contact
                      WHERE Email IN :contactMap.KeySet()]) {
        Contact newContact = contactMap.get(Contact.Email);
        newContact.Email.addError('A Contact with this email '
                               + 'address already exists.');
    }
}

Let me know if you face any issues.

If this solution helps, Please mark it as best answer.

Thanks,
Naveen KNNaveen KN
Just another option, you can go for Duplicate Rules which is purely configuration.