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 

Limiting or Forcing a 1:1 Relationship Between Objects

I want to create 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.

Ispita_NavatarIspita_Navatar

You can have a trigger on the insert event of the child object, which willl check if the existing child count is less than 1 if yes the child will be inserted else an error will be raised.

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.

sales4cesales4ce

Hi,

 

You can achieve this using a workflow.

 

1) Create a custom field on the Custom object. Make the field unique. This field would be used to hold the ID of the associated Opportunity.

2) Create a Workflow rule on the Custom Object.

3) select the evaluation criteria to " Every time a record is created or edited"

4)Then rule criteria as  OpportunityId "does not equal" (Leave the textbox empty)

5)In Workflow action, create a field update.
6) Select the custom field.
7) In the formula editor, select the field OpportunityId
8) click DONE and activate your worflow rule.

 

Hope this helps!

 

Thanks,

Sales4ce

max4904max4904

I like this idea, but I am not familiar with Trigger syntax. What would the code look like/contain to make this work?