Skip to main content
I have a validation rule using a vlookup to ensure the Name field of a custom object is unique.  Here is the rule:

 

Name=VLOOKUP($ObjectType.CustomObjectExample__c.Fields.Name,$ObjectType.CustomObjectExample__c.Fields.Name,Name)

 

This works great...Except...

 

... the object (ie "CustomObjectExample__c")  is the child in a master detail relationship with Accounts (there is a MD Account__c field on the custom object).  The Master Detail allows reparenting (which we want), however when attempting to change the Parent of a CustomObjectExample__c record, the validation rule fires as if there is a duplicate - because we are reparenting. 

 

What is the best thing to add/change with this validation rule to still enforce uniqe value but allow reparting of the record?
2 answers
  1. Nov 6, 2019, 5:50 PM
    How about adding a clause that invalidates the expression?

     

    A clause that says - don't fire when the Master-Detail field is being changed?

     

    Kinda like - 

    NOT(ISCHANGED(MasterDetailField__c))