Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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.

share|improve this question
add comment

2 Answers 2

up vote 8 down vote accepted

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.

share|improve this answer
add comment

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.

share|improve this answer
    
Thanks Bob... i guess trigger is the way to go –  Prady Jan 7 '13 at 14:08
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.