Hello, do you want to know about “How to Create Master Detail relationship in Salesforce?”. In this post we ,will discuss about How to Create Master Detail relationship in Salesforce, Master Detail relationship in Salesforce Error, How to Create Master Detail relationship in Salesforce classic. Salesforce.
Creating Master Detail relationship in Salesforce
The master detail relationship is a type of relationship that creates a tight bonding relationship between the parent object and the child object. Here we call the master object as the parent and the child object as the detail object. Child records must always be associated with the parent, they cannot remain orphaned. Cascade record deletion means that when a parent object record is deleted all its child records are automatically deleted. Standard objects cannot be a detail objects (child object).
For Example- Account (Standard object) cannot be a Detail object.
The master-detail relationship fields are required on the page layout of the detail object. A Roll-up summary fields can be created in the master object (parent object). The child record inherits all security and sharing settings from its parent record.
Master Detail relationship in Salesforce Error
When creating a master detail relationship in salesforce, an error will be displayed like “You cannot create a new master-detail relationship on an existing custom object if the records already exist. First, you need to create a lookup relationship, add a lookup field to all “Records” data, and then change the relationship type to master-detail”. This is because the master detail relationship does not allow for orphan child records. Once if we have a lookup relation with each child having parent then change the field type to master detail relation in child object.
How to create Master Detail relationship in Salesforce?
Creating a Master Detail relationship in Salesforce is very easy. Now we are going to make the relation between crate 1:m pharma product and samples. Here pharma product is parent object and samples is child object. Follow the steps given below.
Go to Setup | Build | Create | Objects.
If we click on Object, a list of custom objects will appear. Click the child object where you want to create a Master-Detail relationship. As shown below
Now go to Sample object and click on it. The item definition page will now appear. Now go to Custom Fields and Relationships.
Now click on the New button to create a new relationship.
Step1:- Choose the filed type.
In Step 1:-
We have to select the field type. Select the master-detail relationship as shown below.
Click on Next between and select the related object.
Step 2:- Select the related object.
We have to select the parent object as the related object. Select the corresponding Pharma object as shown above. Now click on Next button.
Click on the Next button.
Click on the Next button.
Click the Save Button.
Now it is successful to create a master-detail relationship between pharma product and samples. Finally, click the “Save button” to save all the settings.
To check the relationship between the two objects go to the child object (samples). Click on Sample and create new record as shown below.
Since there are no records in the sample, click New to create a new record in the samples.
Enter the Quantity field.
And this is the relation between sample and pharma product. The relationship should always be on the child object. Here sample is child object and the relation is master-detail relationship. Now we need to add a pharma product to the sample as shown above. Now click on save button.
Now that we have successfully created a record in the sample. Make two more records in the samples.
Now click on the Parent Object (Pharma Object).
Go to vitamin D.
Now we see that the new related list is created. This related list is not presented here before the relationship was formed. It is only after the relationship is created that there is a one-to-many relationship between a pharma product and a sample.
Here the pharma product (Vitamin D) is linked to two sample records. We call this relationship the master-detail relationship. In a parent-child relationship, the child record must be associated with the parent. We can create child object record without parent object record. Parent object record is mandatory in creating child object records in salesforce.
Here we clearly understood the Creating Master-Detail relationship in Salesforce. In our upcoming Salesforce tutorials, we’ll learn How to create Lookup relationship in Salesforce.