Skip to main content

Salesforce Basics: Master-Detail vs Lookup in Salesforce

Updated Add a comment
Quick answer: Use a master-detail relationship when the child record means nothing without its parent: it should share the parent's security, be deleted with it, and feed roll-up summary fields. Use a lookup when the child has a life of its own, with its own owner and sharing, and the link to the parent can be optional.

Relationships are how Salesforce connects one object to another, like Accounts to Contacts or Orders to Order Items. The type you pick decides who can see the child records, what happens when a parent is deleted, and whether you get totals for free. Getting it wrong is expensive to fix later, so it pays to decide on purpose.

The Relationship Types in Salesforce

  • Lookup: a loose link. The child can exist without a parent, keeps its own owner, and follows its own sharing rules.
  • Master-detail: a tight link. The child (detail) always needs a parent (master), has no owner of its own, and is deleted along with the master.
  • Many-to-many: built with a junction object, a custom object with two master-detail fields. For example, an Enrollment object links Students to Courses.
  • Hierarchical: a special lookup that exists only on the User object, used for chains such as employee to manager.
  • External and indirect lookups: connect Salesforce records with external objects (__x) that Salesforce Connect reads from another system.

Most design decisions come down to the first two, so the rest of this guide compares them.

Master-Detail vs Lookup: Side by Side

BehaviorMaster-detailLookup
Parent requiredAlways. The field is required on every child record.Optional, unless you make the field required.
Owner and sharingNo owner field on the child. Access follows the master record.The child has its own owner, org-wide default and sharing rules.
Deleting the parentDeletes all child records. Undeleting the master brings them back.Clears the field by default. You can also block the delete or, on custom objects, delete the child too.
Roll-up summary fieldsYes: COUNT, SUM, MIN and MAX on the master.No. Use Flow, Apex or a roll-up tool instead.
Moving a child to another parentBlocked unless you turn on "Allow reparenting."Allowed.
Limits2 master-detail fields per object.Up to 40 relationship fields per object (lookups and master-detail combined).

How to Choose: Three Questions

  1. Does the child mean anything without the parent? If not, lean toward master-detail.
  2. Should people see the child only when they can see the parent? Master-detail gives you that automatically. If the child needs its own owner or sharing rules, use a lookup.
  3. Do you need live totals on the parent? Native roll-up summary fields only work with master-detail.
Example: An invoice line has no meaning without its invoice, so use master-detail. Delete the invoice and its lines go too, and "Invoice Total" becomes a simple roll-up summary field. A contact's "Preferred Hotel" is different: if the hotel record is deleted, the contact should stay, so use a lookup.
Real-life example: the roll-up that cost a sprint

A delivery app needed every Route record to show how many Deliveries it carried, always up to date.

What the team did: They had built Route to Delivery as a lookup. Lookups have no roll-up summary fields, so they wrote a trigger to count children on insert, subtract on delete, recount on reparent, and handle undelete and bulk loads.

Why it hurt: They were rebuilding a feature the platform already offers. Every missed edge case showed a wrong number on a manager's screen, and people stopped trusting the page.

What fixed it: They asked the real questions. Is a Delivery meaningless without its Route? Yes. Should deleting a Route delete its Deliveries? Yes. So they switched to master-detail and added a COUNT roll-up summary field. Salesforce now keeps the number right through deletes, undeletes and reparenting.

The lesson: choose the relationship for the behavior you need (ownership, deletion and roll-ups), not for how the line looks on a diagram.

How to Create a Master-Detail Relationship

  1. Go to Setup > Object Manager and open the child object. The field always lives on the child.
  2. Click Fields & Relationships > New.
  3. Choose Master-Detail Relationship and click Next.
  4. Pick the master object.
  5. Set the field label and name. Then decide two settings:
    • Sharing setting: whether users need Read or Read/Write access to the master to create, edit or delete child records.
    • Allow reparenting: leave it off unless child records really need to move between parents.
  6. Choose page layouts and save.
Watch out: you can't add master-detail to an object that already has records. Every existing child would start with an empty required field. Instead, create a lookup first, fill in the parent on every record (with Data Loader or a batch job), then change the field type to master-detail. Also remember that a standard object can't be the detail side when a custom object is the master.

Many-to-Many: The Junction Object Pattern

When each record on one side can link to many records on the other, add a junction object between them. In a recruiting app, one candidate can apply for many positions, and one position gets many candidates:

  1. Create the two objects: Candidate__c and Position__c.
  2. Create the junction object Job_Application__c.
  3. On Job_Application__c, add a master-detail field to Candidate__c. The first one you create becomes the primary master, and the junction record takes its owner from it.
  4. Add a second master-detail field to Position__c.

Because a junction object needs both master-detail slots, don't spend one on a relationship that a lookup would handle well. For limits and design rules, see Junction Objects and Schema Limits.

Roll-Ups Without Master-Detail

Sometimes the child needs its own sharing but the parent still needs totals. Keep the lookup and build the roll-up another way:

  • Record-triggered flow (after save): fine for simple counts and sums at low volume.
  • Apex trigger with aggregate queries: the right choice for high volume. Make sure it handles bulk loads, deletes, undeletes and reparenting.
  • Scheduled batch Apex: good for busy objects where a total that is a few minutes old is acceptable.
  • Declarative Lookup Rollup Summaries (DLRS): a free, open-source tool that adds roll-ups to lookups without code.

The trade-off: real-time roll-ups use governor limits during every save, while scheduled ones keep saves fast but show slightly older numbers.

Best Practices and Limits

  • Avoid data skew: keep fewer than about 10,000 child records under one parent. Saving a child locks its parent, so huge families cause lock errors and slow sharing recalculation during bulk updates.
  • Use cross-object formulas: a formula field can read fields up to 10 relationships away, so you often don't need to copy parent values with automation.
  • Mind roll-up limits: an object can have 25 roll-up summary fields by default.
  • Plan deletes on purpose: for every lookup, choose whether deleting the parent clears the field, is blocked, or deletes the child.
  • Remember the depth limit: master-detail chains can go at most three levels deep (master, detail, subdetail).
360 Card: Master-Detail vs Lookup
  • Rule: master-detail when the child can't exist alone, lookup when it can.
  • What you gain with master-detail: cascade delete, roll-up summary fields, sharing from the parent, and a required parent.
  • What you give up: the child's own owner, sharing model and independent life.
  • Limits: 2 master-detail fields per object, 40 relationship fields in total, 25 roll-up summary fields by default.
  • At scale: every child save locks the parent, so watch out for parents with thousands of children.
Easy way to remember: dependent child, shared security, needs totals → master-detail. Independent child, own sharing, optional link → lookup.

Core Q&A

Q: How do you decide between master-detail and lookup for a new relationship?

A: Ask whether the child can exist without the parent, whether its visibility should follow the parent, and whether you need roll-up summary fields. Three yeses point to master-detail. If the child needs its own owner or sharing, use a lookup.

Q: What happens to child records when you delete a master record?

A: Salesforce deletes all of its detail records too. If you undelete the master from the Recycle Bin, the detail records come back with it.

Q: How many master-detail relationships can an object have?

A: Two. An object can have up to 40 relationship fields in total, lookups and master-detail combined.

Q: How do you convert a lookup with 2 million records to master-detail?

A: First make sure every record has a parent, because empty values block the change. Then accept that the child loses its own owner: sharing rules, reports and assignment logic based on the child's owner will stop working. With 2 million records, sharing recalculation is heavy, so do it outside business hours. For very large orgs, ask Salesforce Support about deferring sharing calculations during the change.

Q: The child needs its own sharing, but the parent needs totals. What can you do?

A: Keep the lookup and build the totals with a record-triggered flow, an Apex trigger, scheduled batch Apex or the DLRS tool. Pick based on volume and on how fresh the numbers must be.

Q: Can a standard object be the detail side of a master-detail relationship?

A: Not with a custom object as the master. Standard objects can be the master of a custom object, and some standard objects have built-in parent-child links of their own.

Key takeaway: pick the relationship for the behavior you need. Master-detail ties the child's security, life and totals to its parent. A lookup keeps the child independent.

Was this article helpful?

Have a question or spotted a mistake? Ask here about this article

Found this guide useful? Buy me a coffee (opens in a new tab)

Comments

Questions, corrections and your own experience are all welcome.