Convert Lookup to Master-Detail in Salesforce

In Salesforce, when we create the lookup relationship between the Objects, but later on, sometimes when we need characteristics like MDR, then we can convert the lookup relationship into a master-detail relationship.

In this Salesforce tutorial, we will learn to convert a Lookup to a Master-Detail in Salesforce. We will explore the Lookup Relationship and MDR (Master-Detail relationship), understanding why transformation is necessary.

Additionally, we will see how to convert the lookup relationship into a master-detail relationship in Salesforce.

Lookup Relationship in Salesforce

In Salesforce, when we want to access data from the parent object to the child object, a relationship is used. There are two types of Lookup Relationships: one-to-one and one-to-many.

It is recommended to establish a one-to-many lookup relationship. In this case, a lookup field is not required.

Master-Detail Relationship in Salesforce

The MDR field is required in the master-detail relationship because a child object cannot exist without the parent object. When we delete the parent record, the child record is automatically deleted in the master-detail relationship.

In the master-detail relationship, we can use the Rollup Summary field.

Why do we need to convert the lookup relationship into a master-detail relationship in Salesforce?

In the lookup relationship, we sometimes need to make the lookup field required. Additionally, we want to ensure that when parent records are deleted, the associated records are also automatically deleted. To fulfill this requirement, we convert the lookup into a master-detail relationship.

Important:

When converting the lookup into MDR, we should ensure the lookup field from the child object has an assigned parent value, meaning it cannot be blank.

Example- Convert Lookup into Master-Detail in Salesforce

Using the following steps, we can convert the lookup relationship into a master-detail Relationship.

1. Go to Setup. -> Object Manager. -> Search the object on which the Lookup relationship is present. -> Here, I have Custom Object Student_c.

Convert Lookup to Master-Detail in Salesforce

2. Then click on the Fields and Relationships.

Next, locate the lookup relationship field you have already created and click on it. Here, I have selected the Faculty field.

convert lookup to master detail

3. When you click on the field, you will see the Edit button. When we click on the Edit button, we can make changes to that field.

master detail relationship salesforce

4. Here, we want to change the relationship of that field, so there is an option to Change the Field Type; click on it. Using this option, we can change the Lookup into an MDR relationship.

Convert lookup relationship into masted detail example in Salesforce

5. You can see I clicked on the Master-Detail Relationship option to change Lookup to MDR. Then, I clicked on the Next button.

can we convert lookup relationship to master detail in salesforce

6. In this section, don’t change anything, then click on the Save button. If you have followed all the instructions that we discussed earlier, then this field will be saved. Otherwise, it will give an Error.

How to convert lookup into MDR in Salesforce

7. Here we have an Error. This is because we haven’t considered converting the relationship. Now, we will go back to the manager records to check if we have entered any blank lookup fields.

how to convert lookup to master detail in salesforce

8. Now, we have one blank lookup field; we will assign it a value.

change lookup to master detail salesforce

9. Now, all lookup fields have values so that we can proceed. Again, you need to follow the earlier steps to convert relationships.

how to convert lookup into master detail

10. After converting the relationship successfully, you will see the Faculty Field converted the lookup relationship into a master-detail relationship.

lookup and master detail relationship

This is how we can convert the lookup relationship into the master-detail relationship in Salesforce.

Conclusion

I hope you have an idea about converting a lookup relationship into a master-detail relationship. In that, we have seen the lookup relationship and MDR(Master-Detail relationship), and why there is a need to convert the relationship. We have also seen how to resolve any errors.

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.