Thursday, June 21, 2012

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 ))) 

No comments:

Post a Comment