Intermediate 15 min read

Lookup vs. Master-Detail Relationships

By the end of this lesson, you'll be able to:

  • Distinguish lookup and master-detail relationships
  • Explain how each relationship type affects deletion behavior and sharing

Prerequisites: None — this is the first lesson in the course.

Lookup relationships

A Lookup field links two objects without forcing a strict dependency — the child record can exist without a parent (the field is often optional), deleting the parent doesn't delete the child by default, and the child has its own Organization-Wide Default and sharing, independent of the parent.

Master-detail relationships

The detail record's existence is tied to its master — deleting the master deletes all detail records (cascade delete), the detail has no owner of its own (it inherits access from the master), and Roll-Up Summary fields on the master require a master-detail relationship. Most objects allow up to 2 master-detail relationships.

Nullable lookup vs. required master-detail

-- A lookup: Contact.AccountId is optional, nullable
SELECT Id, LastName, AccountId FROM Contact WHERE AccountId = null

-- A master-detail child (OpportunityLineItem) always has its parent
SELECT Id, OpportunityId FROM OpportunityLineItem

Contacts can exist without an Account because AccountId is a lookup and nullable; OpportunityLineItem's OpportunityId can never be null because it's a master-detail relationship — the child cannot exist without its master.

Exercise

A custom object 'Invoice_Line__c' should always belong to exactly one Invoice__c, be deleted automatically if its Invoice is deleted, and never exist independently. Which relationship type fits, and why?

Show hint

Think about cascade delete and whether the child can ever exist without its parent.

SOQL

Lookup vs. Master-Detail Relationships — Quick Check

1. Which relationship type cascades deletes from parent to child automatically?

2. A detail record in a master-detail relationship has its own independent owner and sharing settings.

3. How many master-detail relationships can an object typically have?

Log in to submit the quiz and save your score.

My Notes

Log in to keep private notes on this lesson.

Questions about this lesson

No questions yet — be the first to ask.

Log in to ask a question about this lesson.

Summary

A lookup relationship loosely connects two objects with independent deletion and sharing; a master-detail relationship tightly couples a detail record's existence, ownership, and sharing to its master.