Search for Duplicates Validation Rule

A common problem for Salesforce users is the accidental creation of duplicate records. Validation rules are often used to check the condition of a record before it is saved. Here is a validation rule we use to prevent the creation of a new record with the same name (unfortunately it only works on custom objects).

It uses the VLOOKUP salesforce formula function which is only available for validation rules (unfortunately). This validation rule has two parts:

1) It looks for a record of the same name
2) It makes sure that the record isn't the exact same record as opposed to just a duplicate. This will happen when a record is edited, the name already exists (as itself) and when saved will trigger the part 1 result.

Here is the rule. Simply replace the object name and field name (which can both be entered automatically when using the formula editor)


and(
    Name = VLOOKUP
       ($ObjectType.Service__c.Fields.Name , $ObjectType.Service__c.Fields.Name, Name ),

    not(
     Id=VLOOKUP
         ($ObjectType.Service__c.Fields.Id , $ObjectType.Service__c.Fields.Name, Name )))

10 comments:

محمود نور الدين said...

How can I use this approach on standard objects,do you have idea?

محمود نور الدين said...

How I can apply this approach to standard object,I am just starting learning,do you have any idea how to iterate over specific field value but on standard object

محمود نور الدين said...

You say (unfortunately it only works on custom objects),

How to use this solution on standard objects.

Anonymous said...

It's Really awesome
Thanks A lot

Anonymous said...

Can you please advise how many custom objects I need to create?

Example:
I have an object (formula text) to show the product name ... does de field name needs to be a custom object too??

Thanks, in advance.

Michael Snapp said...

When I say "custom object", I'm talking about a database, not a field. Like Leads, that is an object (but it is a standard object), so a custom object is for making your own database. So you don't actually need to create any custom objects, but the validation rule you're creating needs to be on a custom object.

If you need help with this, visit our website and fill out the get started page, we can discuss the issue you face and I can suggest a good approach for solving it.

Algrokoz said...

So if I am trying to prevent duplicate records for a custom object that has a text name field that is automatically updated via workflow upon creation, will this validation rule still work?

What do I put in the field spot?

Unknown said...

@Algrokoz: Let me know if you found answer to your question. I have the same question and looking answer.

AKHIL KUMAR VIDIYALA said...

Thank you

akhilapriya404 said...

Nice information thank you,if you want more information please visit our link salesforce Online Training