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
Sumanta Biswas 11Sumanta Biswas 11 

Contact: First Name, Last Name, EmailIf we create same values in the above mentioned field, then give alert message on saving the record

Hi Folks,
I have the below requirment:
Contact: First Name, Last Name, EmailIf we create same values in the above mentioned field, then give alert message on saving the record. It should say same type of record already exist and still should save the record.
 
sachinarorasfsachinarorasf
Hi Sumanta,

With the help of this code you can resolve the above problem:

Try this code:
Create a trigger for the contact:-

trigger Contact_Trigger on Contact(before insert, before update) {
    List<Contact> conRecords = new List<Contact>();
    conRecords = [Select Id, FirstName, LastName, Email From Contact Limit 10000];

    for(Contact con : Trigger.New) {
        for(Contact conLoop: conRecords){
            if( con.FirstName == conLoop.FirstName){
                con.addError('Contact already exist');
            }
            if(con.LastName == conLoop.LastName){
                con.addError('Contact already exist');
            }
            if(con.Email == conLoop.Email){
                con.addError('Contact already exist');
            }
        }
    }
}

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Sachin Arora
www.sachinsf.com