Home  >  Blog  >   Salesforce

Master-detail Relationship in Salesforce

Rating: 5
  
 
13061
  1. Share:
Salesforce Articles

A master-detail relationship defines the relationship between the parent and the child. The master table defines the parent relation and the detail defines the child relation. If the master table is deleted then the child record data is also deleted. The RUS(Roll-Up Summary) fields are also created on master records.

Want to enhance your skills in dealing with the world's best CRM, enroll in our Salesforce Online Course

How To Create Master-detail Relationship (MDR) in SalesForce 

Let us start with an example, create two different Objects for Master-detail relationship, and have a look at the benefits we have in MDR.

Eg: Two Objects.

  • Company Names.
  • Employees.

I have included simple fields for “Company Names & Employees” Objects as shown in the below figure.

Master-detail Relationship in salesforce

For MDR, we need to create a relationship field on one of the Objects. Select for strong relationship bonding not as “Lookup relationship”.

I have taken Employees Object and created an MDR field in it. The process includes,

Click on Employees >> Click “Quick Access Menu” >> Add “New Field”.

Step1: Choose Field Type (Master Detail Relationship) >> Next.

Master-detail Relationship in salesforce

Master-detail Relationship in salesforce

Step2: Select the appropriate Object on which the relationship should be established.(eg: Company name) >> Next.

Master Detail Relationship in salesforce

Step3: Fill in the details and proceed to the next step.

Master Detail Relationship in salesforce

Step4: Provide with all the required security level check and proceed to the next step.

Master Detail Relationship in salesforce

Step5: In this step, we will add a reference field for MDR to the page layout and proceed for next step.

Master-detail Relationship in Salesforce

Step6: In this step, we will add a custom related list of the desired Object and Save.

Master Detail Relationship in salesforce

With the above steps, the MDR relationship is established. The below displays the relationship.

Checkout SalesForce Tutorial

Master Detail Relationship in salesforce

Hence, we can look at the MDR created between the “Company Names and Employees

Let us add, an New Employee to the Object. We can observe that without the “Company Name” entering, it is unable to proceed to the next step. So, click on the magnifying glass located to the field next to enter “Company name”, you can select the company name for which the employee belongs to.

Master Detail Relationship in salesforce

Note: We can create upto 2 MDR in 1 Object. Not more than that.

Master Detail Relationship in salesforce
To look at the MDR, Field Dependency & Cache clear process, let us assume with an example. Let us create some records in the “Employee Object”.

Master-detail Relationship in Salesforce

Let us delete the “Company Name” (eg.Tech Mahindra), from the list and observe the dependency, cascading delete & master-detail relationship work process.

Master Detail Relationship in salesforce
Master-detail Relationship in Salesforce
After deleting the “Tech Mahindra” record from the “Company Names” Object list, the dependent employee’s and their records are also deleted from the “Employees” Object. Whereas this scenario is not possible in “Lookup Relationship

Lookup Relationship in salesforce
Lookup Relationship in salesforce
Lookup Relationship in salesforce
Note: In MDR the master record i.e the owner of the primary record will become the owner the child record another feature that to be considered in the MDR, where it is not available in Lookup Relationship.

Below is the example for the primary and secondary records relations, in which the “Owner” of the “Company Object” becomes the Owner of the “Employees Object”. So, the Owner field is not visible in the assigned company employee record details.

Master Detail Relationship in salesforce

Lookup Relationship Vs Master-Detail Relationship

Lookup Fields:

  • 25 to 40 lookup fields are allowed per Object.
  • The fields are not mandatory.
  • If the parent is deleted the child is not affected.
  • The Object has an owner field.
  • The child has independent sharing & security.
  • It does not allow rollup summary fields.

Master Detail Fields:

  • 2 master detail fields allowed per object.
  • The fields are always mandatory.
  • The Object does not have an owner field.
  • If the parent is deleted the child records are also deleted.
  • The child inherits all the security and sharing from parent.
  • It allows roll-up summary fields.

Few Points About Master-detail Relationship:

  • The relationship is used when we need to connect 2 objects together in strong bonding mode.
  • The dependency is mentioned in such a way that, the primary record controls the secondary record.
  • If the primary record is deleted, the secondary records also delete, hence it is called as “Cascading Delete”.
  • It gives rollup summary which helps to get a summary of child records.

What is Roll-Up Summary.

A roll-up summary determines the values of the related records, whereas in a related list. We can create a roll-up summary to display values of the master record based on field values in the detailed record, and the record must be related to MDR.

How to create Roll-Up Summary?

Let us create a RUS field in the desired “Company” from the list and observe the process.

Click on the “Company Names Object” >> Click on the quick access menu located on the right side of the application area(Org) >> New Field.

Master Detail Relationship in Salesforce

Step 1: Select the “Roll-Up Summary” >> Proceed to the next step.

Roll-Up Summary in Salesforce

Step 2: Enter the details of the field name. (Eg. Maximum Experience)  >> proceed to the next step.

Roll-Up Summary in Salesforce

Step 3: select the summarised object. (Eg. Employees) >> Select the Roll Up type. (Eg. Max) >> select the field to aggregate. (Eg. Experience) >> Filter Criteria (Eg. All records) >> Proceed to next step.

Roll-Up Summary in Salesforce

Note: In filter criteria, the other option is used for filtering based on operator and values.

Roll-Up Summary in Salesforce

Step 4: In this step select who all can visualize the RUS field. >> proceed to next step.

Roll-Up Summary in Salesforce

Step 5: In this step the default selection of “Add the Page layout” >> proceed to Save button.

Roll-Up Summary in Salesforce

The Roll-Up Summary field in the “Company Names” displays the highest experience number in the “Maximum Experience” field in the “Company Names” object.

Roll-Up Summary in Salesforce

What is Reparenting?

Reparenting allows you to edit the parent details of the Object, which is not allowed to edit.(Eg.Employee).

Checkout Salesforce Interview Questions

How to create Reparenting?

Click on the “Employee” Object edit >> Custom fields and relationships >> Edit >> master-Detail Options >> Allow Reparenting >> Save.

Reparenting in Salesforce

After Save Go to Employees Object >> Select Employee >> Edit >> Option to select Company Name.

Reparenting in Salesforce


Reparenting in salesforce

Checkout SalesForce Sample Resumes

Reparenting in Salesforce

In the next topics, we will discuss in detail about “Salesforce Security”. Keep following us for more info on Salesforce Administration.

Mindmajix offers different Salesforce certification training according to your desire with hands-on experience on Salesforce concepts

Salesforce Administration Training Salesforce Lightning Training 
Salesforce Advanced Developer Training Salesforce Developer Training 
Salesforce IoT Training Salesforce App Builder Certification Training 
Salesforce AppExchange Training Salesforce Service Cloud Training 
and many more.  
Join our newsletter
inbox

Stay updated with our newsletter, packed with Tutorials, Interview Questions, How-to's, Tips & Tricks, Latest Trends & Updates, and more ➤ Straight to your inbox!

Course Schedule
NameDates
Salesforce TrainingApr 27 to May 12View Details
Salesforce TrainingApr 30 to May 15View Details
Salesforce TrainingMay 04 to May 19View Details
Salesforce TrainingMay 07 to May 22View Details
Last updated: 03 Apr 2023
About Author

Arogyalokesh is a Technical Content Writer and manages content creation on various IT platforms at Mindmajix. He is dedicated to creating useful and engaging content on Salesforce, Blockchain, Docker, SQL Server, Tangle, Jira, and few other technologies. Get in touch with him on LinkedIn and Twitter.

read more
Recommended Courses

1 / 15