Master-Detail Relationship

A Master-Detail Relationship in Salesforce tightly links a child (detail) object to a parent (master) object so that the master controls the detail’s ownership, security, and lifecycle. Detail records inherit the master’s owner, follow its sharing settings, and are deleted automatically when the master is deleted. The relationship field is always required on the detail record at the data-model level, not just on the page layout.The master object can be a standard or custom object. When creating a custom Master-Detail relationship, the detail object must be a custom object.  The master can be a standard or custom object, but the detail must always be a custom object.

You’ll meet this term whenever a child object cannot exist without its parent: Project Tasks tied to a Project or Expenses tied to an Expense Report.

PRACTICAL EXAMPLE

A consulting firm uses a custom Project object for client engagements and a custom Project Task object for individual work items. Each task must belong to a specific project, must inherit who can see it from the project, and must be deleted when the project is deleted. Each task must belong to a specific project, must inherit who can see it from the project, and must be deleted when the project is closed. The admin creates a Master-Detail relationship from Project Task to Project. Anyone who can access a Project can also access its tasks. If a Project is deleted, its related Project Tasks are deleted and moved to the Recycle Bin.

Quick facts

  • Cascade delete: deleting a master record automatically deletes all detail and subdetail records (moved to Recycle Bin). Undeleting the master restores them.

  • Owner field is not available on detail records: ownership is inherited from the master. Detail records cannot have sharing rules, manual sharing, or queues.

  • Security inherits from master: Detail and subdetail records inherit record-level access from the master record. Record-level sharing can’t be configured independently on detail records.

  • Relationship field is required: The Master-Detail field is required at the data-model level, not just on the page layout.

  • 2 master-detail relationships per custom object, 40 total relationships (including both Lookup and Master-Detail relationships.)

  • Up to three levels: Master-Detail relationships can extend from master to detail to subdetail.

  • Master and detail objects: When creating a Master-Detail relationship, the master object can be standard or custom, but the detail object must be a custom object.

  • After a Master-Detail relationship is created, the parent object (“Related To”) cannot be changed.

  • By default, records cannot be reparented. Admins can enable “Allow reparenting” in the relationship definition if needed.

Warning icon

Note

You cannot create a Master-Detail relationship on a custom object that already contains records. Salesforce blocks this with the error: “You must first create a Lookup relationship, populate the lookup field with data in all records, and then change the relationship type to Master-Detail.” Plan the relationship at object creation time when possible.

FAQ

What's the difference between Master-Detail and Lookup Relationships in Salesforce?

Master-Detail tightly couples the detail record to the master: the detail inherits ownership and sharing from the master, and gets deleted automatically when the master is deleted. Lookup is a looser link: the child has its own owner, its own sharing, and survives if the parent is deleted (with options to clear the field, block deletion, or cascade-delete). Master-Detail supports roll-up summary fields on the master; Lookup does not(you'd reach for a tool like DLRS).


How to convert Lookup Relationship to Master-Detail in Salesforce?

To convert a Lookup relationship to Master-Detail, the lookup field must contain a value on every existing child record. Records with blank lookup values prevent the conversion. After conversion, detail records no longer have their own owner or independent sharing. Ownership and record-level access are inherited from the master record. Sharing rules on the detail object no longer apply. Native roll-up summary fields become available on the master object.


How to change Master-Detail Relationship to Lookup in Salesforce?

How to change Master-Detail Relationship to Lookup in Salesforce? Before conversion, remove any roll-up summary fields on the master that reference this relationship. After conversion, detail records get their own Owner field and can have independent sharing. Sharing rules can then be set on the former detail object. Cascade delete stops being automatic.


How to delete master detail relationship in Salesforce?

Go to Object Manager, open the detail object, find the Master-Detail field, and delete it. Before deletion, Salesforce requires removing any roll-up summary fields on the master that reference this relationship. The detail records are not deleted; only the relationship field is removed. The field stays in "Deleted Fields" for 15 days and can be restored.