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
Adam KrausAdam Kraus 

Need help with Preventing Duplicates

I have a custom object called Address that has a picklist called Address Type. I need to prevent a record from saving with the Address Type of "Home" if a record for that specific parent object already has an Address record with the Address Type of "Home". How can I create that validation rule?

Let me know if you need more info and please keep in mind that I have 0 Apex coding knowledge.  Thanks!
Best Answer chosen by Adam Kraus
Bhanu MaheshBhanu Mahesh
Hi Adams,

You can prevent duplicate records by using unique text field and a workflow.

Refer the below link how to acheive this

http://focusonforce.com/configuration/preventing-duplicate-records-with-salesforce-config/

For your requirement you have to update the field only when the Address type is 'Home'

So the formula for your field update will be 

if(ISPICKVAL(Address_Type__c,'Home'),parent Id + TEXT(Address_Type__c),'')

If are not ok doing with the above work around, then you have to go for trigger.

Let me know if you need any help.

Mark this as "SOLVED" if your query is answered

Regards,
Bhanu Mahesh

All Answers

Bhanu MaheshBhanu Mahesh
Hi Adams,

You can prevent duplicate records by using unique text field and a workflow.

Refer the below link how to acheive this

http://focusonforce.com/configuration/preventing-duplicate-records-with-salesforce-config/

For your requirement you have to update the field only when the Address type is 'Home'

So the formula for your field update will be 

if(ISPICKVAL(Address_Type__c,'Home'),parent Id + TEXT(Address_Type__c),'')

If are not ok doing with the above work around, then you have to go for trigger.

Let me know if you need any help.

Mark this as "SOLVED" if your query is answered

Regards,
Bhanu Mahesh
This was selected as the best answer
Adam KrausAdam Kraus
Thanks Bhanu!

The only thing I would add to this is that I had to create a 2nd Workflow that will blank out the Unique Key field if the Address Type is not equal to "Home", so that I am still able to add multiple "Business" Address Type records, for example.

Let me know if you think I can accomplish all this in 1 workflow as opposed to 2.