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
MC-DragnierMC-Dragnier 

Validation Rule to Check for Duplicate Record Names

I have the following validation rule written thus far to use a Vlookup on a custom object to verify that another record has not been created with the same name

 

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

 

This indexes against all other Finale Assets to confirm the name is not the same and then does a check to make sure that it is not producing an error message because it found itself.

 

I need to expand this to include another field, a picklist with different asset types.

 

Ultimately the rule should work as follows.

 

An individual can not create a new record with the same name and type as an existing record.  A record can have the same name and a different type.

We could have Name = Doc A  Type = Document and Name = Doc A Type = Rule but not

 

Name = Doc A Type = Document and Name = Doc A  Type = Document.

 

Can anybody provide some assistance in getting the picklist portion of the rule included in this validation rule.  Where I'm coming across trouble is becuase it is a picklist, there is a limited number of formulas to try and work around this with, since we can't do another VLOOKUP against a picklist.

 

Thanks!

tedwardtedward

Not sure that vlookup validation rules are the way forward in this situation.  However,

 

You could use the following method for a code free solution:

 

1.  Create a custom text field (Key__c) on the custom object and set it to be unique ie. check "Do not allow duplicate values"

 

2.  Create a new field update and use a formula to set the value for the Key__c field to a concatenation of the record name and the picklist value. Eg,   "Name  &  TEXT(Asset_Type__c)"

 

3.  Create a new workflow rule that actions the field update you created when records are either created or amended.

 

Record creation/edit will then fail if the Name, Asset Type combination is duplicated.

 

If you have existing data in the custom object you will also need to do a data fix to ensure the existing records have the key field populated.

 

Hope this helps,

kponnkponn

How do I set to "Not allow Duplicate Values for a Formula Field in Custom Object?

harish s 33harish s 33
Hi,

While creating new field , in the step-2, we can find " [ ]Do not allow duplicate values".
You have to Enable it.

Hope this helps