Cert++
Close

Master-detail versus lookup for object extension

Key Takeaway

Choose master-detail when the parent must control the child's deletion, ownership and security, or when the parent needs a roll-up summary field. Lookups don't support roll-up summary fields.

Master-detail and lookup are the two main ways to link objects in Salesforce. You build either one by adding a custom relationship field to the child object. Master-detail ties the child closely to its parent, so the parent controls deletion, ownership and security. A lookup is a looser link that doesn't support sharing or roll-up summary fields. The relationship type decides how the two objects handle data deletion, sharing and required fields on page layouts, so pick the type before you build.

How master-detail works

In a master-detail relationship, the master record controls the detail record. In a multilevel master-detail relationship, a detail record can also have its own child records, called subdetail records.

Deleting a master record also deletes its detail and subdetail records. Undeleting the master restores them. Deleting a detail record works differently. Salesforce only sends the detail record to the Recycle Bin and leaves the master intact. If you delete a detail record and later delete its master separately, you can't undelete the detail record, because it no longer has a master to relate to.

Detail and subdetail records have no Owner field of their own. Salesforce sets the owner automatically to the master's owner. Detail records inherit security settings and permissions from the master. You can't set permissions on the detail record independently.

Custom objects on the detail side of a master-detail relationship can't have sharing rules, manual sharing or queues, because those features need the Owner field. If records must go to a queue or have their own sharing rules, a lookup is the right choice.

The master-detail field is required on the detail record's page layout, so every detail record must have a master. By default, detail records can't be reparented to a different master. On custom objects, an admin can allow reparenting by selecting "Allow reparenting" in the master-detail relationship definition.

A dive school builds two custom objects, Dive Trip and Dive Log. Dive Log has a master-detail field that points to Dive Trip. Priya owns the Dive Trip record "Reef Morning." Each Dive Log for that trip has Priya as its owner, because the owner comes from the master. When the trip is canceled, Priya deletes "Reef Morning." Salesforce deletes the trip's Dive Logs at the same time. A week later, Priya undeletes the trip, and the Dive Logs come back with it. If she had deleted one Dive Log on its own, "Reef Morning" would have stayed in place.

Platform Administrator II Study Guide

Checklist progress

0/290Learned

Given a scenario, determine the appropriate solution to enhance or extend objects (master-detail, lookup, junction object, related list, record type, Schema Builder, and Object Creator)

0/15

Prepare for the Exam

Play Today's Certle

Study Community

Ask questions and get the latest info from other Platform Administrator II studiers.