+ Start a Discussion

Forcing a 1:1 Relationship Between Objects

I’ve created a new custom object that relates to the Opportunity object.  I only want there to be one entry per Opportunity. I'd like to find a way to limit the relationship to be 1:1 only.  I’ve created a Master-Detail relationship between the new object and the Opportunity object, but that doesn’t appear to limit the entries for the relationship. What settings or methods can I use to make this work?



Best Answer chosen by Admin (Salesforce Developers) 

You should be able to accomplish this with a combination of a validation rule and a roll up summary field.


Put the roll up summary field on the parent object (the opportunity). This field will count the number of child objects.


Then, put the validation rule on the parent object that checks the value of the roll up.


Note: this approach will only work for objects in a master-detail relationship. If the objects are in a lookup relationship, you'd need to use Apex to enforce the 1:1 relationship.