I have a custom object with name and a lookup to contact among other fields. The need that i have is that i need to make sure that only record name should not be duplicated for a contact.

There can be duplicate names as long as its not the same contact. We should not allow duplicate names for the same contact.

Can we achieve this using validation rules? I am trying to avoid using triggers if this can be achieved using validation rules.

2 Answers 2


You can do it with workflows as below:

Create a custom field, mark it as Unique. Now write a workflow field update to update this custom field with concatenation of Contact's 15 or 18-digit Id and Name field.

This way you count on sales-force's native uniqueness validation to prevent dupes instead of coding it.

Hope that this helps.


So if I understand correctly, when a new custom object is inserted, you want to ensure that its name is unique within those associated with a particular contact?

Unfortunately, I think you will have to resort to a trigger for this.

It is tempting to assume that you can do this via the VLOOKUP function, but this won't allow you to constrain the records that you consider to those associated with the contact.

I've also tried using a field on the custom object set via workflow to a concatenation of the contact name and custom object name, and then using a VLOOKUP function in a validation rule to ensure that this is globally unique.

However, as per the Triggers and Order of Execution in the Apex Developer's Guide, my custom validation rule didn't fire after the update.

11 . If the record was updated with workflow field updates, fires before and after triggers one more time (and only one more time), in addition to standard validations. Custom validation rules are not run again.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .