What is the best way to create 1:1 relationship in Force.com. I have an Object A. What i need to create is another object B, which will be like an extension to this object. Since there are already large number of fields on object A, i want to created related set of fields in another object B. When a record in Object A gets saved, i want to make sure that there is one and only one related record in Object B. I dont want to use triggers for validation and want to achieve this only through clicks.


Prior to Spring 15, this was not possible without Apex code. Just to clarify the part that is key:

When a record in Object A [the parent] gets saved, i want to make sure that there is one and only one related record in Object B [the child].

This is different from making sure that the child is only related to a single parent. This is ensuring that every time a parent record is created, you also create a child, and that there only is ever one child.

This would also assume that you would want to ensure that any time the parent is deleted, the child would be deleted.

You would also want to prevent the child from ever being deleted unless the parent is being deleted.

Finally that you would never want the child to be reparented (assigned a new parent record).

With the new Lightning Process Builder tool, this is possible, along with a few old tried and true tricks.

  1. Parent__c object and Child__c objects are created.
  2. In Child__c add a Master-Detail relationship.
  3. In the relationship, ensure you do not allow reparenting (this is default anyway, but just be sure!)
  4. A roll-up summary field in the parent to count children.
  5. With Lightning Process Builder, create a new process. In that process make it so that everytime you create a Parent__c record, a new Child__c is created and assign the Parent__c.Id value to the M-D relationship field. (Don't forget to activate it.)
  6. Create a validation rule that ensures your RSF never is more than 1, and on update only is never less than 1.

Above, Step 5 ensures that everytime a Parent__c record is created the child is created, too, with the unique text field populated. This is the new part.

Step 6 ensures that when someone attempts to create a second Child__c record for the same Parent__c the second attempted child will fail. It also ensures that the child is never deleted (on update never less than 1 will ensure that the child always sticks around). This isn't particularly new, but with the M-D field, I find the roll-up summary field validation approach is a much more clean way of ensuring a unique child record.

  • This solution does not work where you need a standard object to be the child object. – Jan Julian Mar 5 '15 at 16:38

I think, and I have not done this, but you could create a unique text field to hold the Id of the parent object (Object A) and then populate it with a workflow.


Assume one Chinese Parent can have only 1 Chinese Child. 1) First create the parent object - Chinese Parent

2) Create the child object - Chinese Child

3) Create the 1:M relationship between the 2 objects

4) Create a field named 'Parent Id' on the child object and make it required

5) Create a Workflow Rule One2One Relationship on child object Rule Criteria - Chinese Child: Chinese Child Name not equal to null Evaluation Criteria - Evaluate the rule when a record is created

6) Then create a Workflow Action Field Update Action: Parent Id update Field to Update Chinese Child: Parent Id Formula Value Chinese_Parent__r.Id

Test it creating a parent record, a child record then again a child record with the same parent. You would get an error - Duplicate value on record as we made the Parent Id as unique on the child object in step no. 4

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.