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
max4904max4904 

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?

 

Thanks.

Best Answer chosen by Admin (Salesforce Developers) 
stwdevstwdev

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.