+ Start a Discussion

How to avoid duplication of records based on 3 fields (data type:Text)

i have a scnario:3 fields (data type:Text) First Name,Middle Name,Last Name, if any Duplicate record is going to be created with same values in those three fields, that operation should fail by throwing an error,Is there any possible way to achieve this,through (UI configuration or trigger),
I wonder..how to compare text fields that too 3 Text fields.
David ZhuDavid Zhu
You can create a formula text field concatenating three fields.
Then add a validation rule to prvent the duplication.

ie. fomula field: concatenatingField.
in validationg rule, check condition: PRIORVALUE( concatenatingField__c ) = concatenatingField__c to prevent the duplication.
Sridhar BonagiriSridhar Bonagiri

Can you try the below code through trigger.

String errorMsg ='A Contact with these values already exists';

    Map<String, Contact> ContactMap1 = new Map<String, Contact>();
    Map<String, Contact> ContactMap2 = new Map<String, Contact>();
    Map<String, Contact> ContactMap3 = new Map<String, Contact>();
    for (Contact Contact : System.Trigger.new)
        if (System.Trigger.isInsert || (System.Trigger.isUpdate &&
                    (Contact.FirstName != System.Trigger.oldMap.get(Contact.Id).FirstName || Contact.LastName != System.Trigger.oldMap.get(Contact.Id).LastName || Contact.MiddleName != System.Trigger.oldMap.get(Contact.Id).MiddleName)))
            // Make sure another new Contact isn't also a duplicate 
            if (ContactMap1.containsKey(Contact.FirstName) && ContactMap2.containsKey(Contact.LastName) && ContactMap3.containsKey(Contact.MiddleName) )
    // Using a single database query, find all the Contacts in 
    // the database that are having same FirstName,LastName and MiddleName as any 
    // of the Contacts being inserted or updated. 
    for (Contact Contact : [SELECT FirstName,LastName,MiddleName FROM Contact where FirstName IN:ContactMap1.KeySet() and LastName IN:ContactMap2.keySet() and MiddleName IN:ContactMap3.keySet()])

        Contact newContact = ContactMap1.get(Contact.FirstName);

Sridhar Bonagiri
You can do this by standard process by creation a unique field.

Here are the steps:
1.Create a unique field of type text.
2. While creatig check don't allow duplicate on the field creation definition.
3. Write a workflow rule to put the concatenated value of the three fields that you don't want to have duplicates.

By doing above process, whenever a new records is going to be created unique field that you will create will not allow user to insert the data.

Hope this helps, let me know if you have further issues

mark this as best answers if this helps, for helping others