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
prashanth murukondaprashanth murukonda 

What is ONE to ONE Relationship?

Can anyone please tell me how to do One to One Relationship?
Apoorv Saxena 4Apoorv Saxena 4
Hi Prashanth,

Salesforce allows One to many and Many to many Relationships .But you can establish  a one to one relationship by follwing steps
  • Create a master detail relationship between two Object.
  • On master object create a  rollup summary field which count the child records
  • Now write trigger on child Object which checks if the rollup summary count on master is equal to one then throw an error that the master have already one record attached select another.

This way every master Object will only have one record of the other object associated, hence one to one relationship is established.

Please let me know if this helps!


Priyanka S 27Priyanka S 27
Hi Prashanth,

Create a master detail relationship between two objects and create a roll up summary field on parent object to get the count of child records. Create a validation rule on child object and check the roll up count of parent record is greater than 1 or not. If so then throw an error message on child object.

This will prevent insertion of more than one child records to be associated with the parent record.

Priyanka S