Master-Detail Relationship in Salesforce

I worked for an organization that uses Salesforce CRM to manage the employee management application.

Recently, HR asked me to update the application to include an employee field for reimbursement applications. When the employee clicks that field, it shows all employees in the list, and without filling that field, the record should not get saved.

To achieve that requirement in Salesforce, we have a master-detail relationship field. Here, I will explain master-detail relationships in Salesforce, and then I will explain how to create master-detail relationships in Salesforce.

Master-Detail Relationship in Salesforce

In Salesforce, the master-detail relationship allows us to access data from one object to another. We used parent-child terminology to access parent records in the child object. It is a strongly coupled relationship, which means it allows the parent to control the child’s records.

Salesforce allows us to create master-detail relationships in the Professional, Enterprise, Performance, Unlimited, and Developer editions. We can create a master-detail relationship in both the Salesforce Lightning and Salesforce Classic user interfaces.

Characteristics of Master-Detail Relationships:

  • We create MDR on many sides of an object. The MDR field is always required.
  • In MDR, the child object’s records don’t exist without the parent, which means that when the parent records are deleted, the child records associated with the parent are also deleted.
  • We can create only two MDRs per object. When we use this, we have the option to use the rollup summary field.
  • We can use the roll-up summary field on the parent object.

Use of Master-Detail Relationship in Salesforce

In Salesforce, we can use MDR to access the parent records in the child object or to apply the cross-object formula. Also, to enhance security between two objects, if parent records are deleted, then child records should also be deleted; we can use MDR.

  • It is a strongly coupled relationship.
  • The roll-up summary field is available when using MDR.
  • The child inherits all the security and sharing from the parent object.

Important:

When creating the master-detail relationship, consider that MDR can only be created on an object with no existing records. Otherwise, it will give an error.

If that object already has records, first, we need to create a lookup relationship and then convert it into a master-detail relationship.

Create Master-Detail Relationship in Salesforce

Using the above scenario, I explained how to create master-detail relationships in Salesforce in the following steps.

  1. Go to the Setup option, select the Object Manager tab, and search for the object on which you want to create a master-detail relationship. Here, I selected a custom object named Reimbursement.
master detail relationship in salesforce
  1. To create the new field, we have the New option. Click on that option.
Master-Detail Relationship in Salesforce
  1. Then, in the Data Type list, you can see the field Master-Detail Relationship. Click on it, then click on the Next button to set the next steps.
Create Master-Detail Relationship in Salesforce
  1. Here, you need to select Related Object, where you can select another object with which you want to create a relationship. That will be the Parent object of this reimbursement object. Then click on the Next button.
Use of master-detail relationship in Salesforce
  1. Here, you can set a Field Label; this label will display the record details page. I have entered Employee as a label. The Field Name automatically populates this with the  API  name. Then click on the Next button.
master detail relationship salesforce
  1. In the Establish field-level security for reference field section, we give visibility to the profiles. As the MDR field is required, it is visible to all profiles by default. Here, we click on the Next button.
salesforce master detail relationship
  1. In the Related List Label, you need to give the name you want to display as a related list on the Record Page. After that, click on the Save button to create MDR.
master-detail relationship salesforce
  1. In the Field & Relationship of the reimbursement object, the Employee field has been created with a master-detail relationship.
what is master detail relationship in salesforce
  1. Now navigate to the object tab on which you created the MDR and click on the New button to create a record. You will see that the Employee field has been added and is required.

When you click on that field, the employee list pops up, and you can select the employee from that list.

salesforce master-detail relationship

In this way, we can create a master-detail relationship to establish the relationship between two objects in Salesforce.

Conclusion

I hope you have an idea about creating the master-detail relationship in Salesforce. In that, we have seen what the master-detail relationship is, when we can use it, the characteristics of MDR, and its uses in Salesforce.

We have also seen which important points to consider while creating the master-detail relationship. Additionally, we have seen how to create a master-detail relationship in Salesforce with examples and step-by-step explanations.

You may like to read:

Agentforce in Salesforce

DOWNLOAD FREE AGENTFORCE EBOOK

Start with AgentForce in Salesforce. Create your first agent and deploy to your Salesforce Org.

Salesforce flows complete guide

FREE SALESFORCE FLOW EBOOK

Learn how to work with flows in Salesforce with 5 different real time examples.