A master-detail relationship in Salesforce is a tightly coupled parent-child relationship where the detail (child) record cannot exist without its master (parent) record. The master controls the detail’s ownership, sharing, and lifecycle: deleting the master cascades to all its details, the detail inherits the master’s owner, and the OWD on the detail is locked to “Controlled by Parent.” Master-detail is the only relationship type that enables built-in roll-up summary fields.
What the relationship enforces
When you create a master-detail field on the child object pointing to the parent:
- The master-detail field is always required — you cannot save a child record without a parent.
- The child’s
OwnerIdfield disappears — there is no separate owner; the parent’s owner is effectively the child’s owner. - The child’s OWD is locked to “Controlled by Parent” — sharing settings on the child come from the parent.
- Deleting the master record cascades the deletion to all detail records (and their details, recursively up to 3 levels deep).
- The child appears in the master’s related list by default.
- The master object can have roll-up summary fields counting or summarizing child fields.
When master-detail is the right choice
Master-detail is appropriate when the child is conceptually part of the parent — when no business meaning exists for the child without the parent.
Classic master-detail relationships:
- Opportunity Line Item → Opportunity (standard, ships this way)
- Case Comment → Case (standard)
- Order Product → Order (standard)
- Invoice Line Item → Invoice (custom, common pattern)
- Project Task → Project (custom)
- Survey Question → Survey (custom)
- Attendee → Event Session (custom)
If you’re tempted to model an “Account → Opportunity” master-detail because you want a roll-up summary of Opportunity Amount on Account — don’t. Salesforce intentionally made that a lookup because Opportunities have independent ownership, lifecycle, and sharing from their Accounts. Modeling it as master-detail would be a serious data-model mistake.
Key constraints
| Constraint | Detail |
|---|---|
| Max master-detail relationships per object | 2 (each object can be the detail of up to 2 masters) |
| Total relationship limit per object | 40 (master-detail + lookup combined) |
Detail object’s OwnerId | Does not exist — owner is inherited from master |
| Detail object’s own sharing rules | Cannot create — sharing is controlled by parent |
| Reparenting (changing the parent) | Disabled by default; enabled via “Allow reparenting” checkbox on the field. When enabled, sharing is recalculated on reparent. |
| Standard object as detail | Generally not allowed — most standard objects cannot be made the detail in a custom master-detail. Standard objects can be the master with custom detail. |
| Detail-to-detail (3-level) | Allowed — a detail object can be the master of another detail. Cascades flow down. |
Master-detail and roll-up summaries
Master-detail unlocks roll-up summary fields on the master. You can create up to 25 roll-up summary fields per object (limit may shift between releases — check current docs). They support:
COUNT— number of detail recordsSUM— total of a numeric field on detailsMIN/MAX— smallest/largest value across details
You can filter the rolled-up records by criteria (e.g., only roll up Closed Won opportunities, only roll up open tasks).
Invoice (master)
├── Invoice Line Item (detail)
│ Quantity__c, Unit_Price__c, Line_Total__c
└── Roll-Up Summary on Invoice:
Total_Amount__c = SUM(Invoice Line Item.Line_Total__c)
Line_Count__c = COUNT(Invoice Line Item)
Roll-up summaries are not available on lookup relationships — that’s the single biggest reason to choose master-detail when the data shape supports it.
Converting between lookup and master-detail
You can convert in either direction, but with strict conditions:
- Lookup → Master-Detail: every existing child record must have a value in the lookup field (no nulls). Salesforce blocks the conversion otherwise.
- Master-Detail → Lookup: any roll-up summary fields on the master that depend on the detail must be deleted first.
If you’re building a new object and might need roll-up later, starting with lookup and converting to master-detail is a common pattern — just be aware of the no-nulls constraint when the time comes.
Real-world scenario
“You need to model Quotes and Quote Line Items, and the Quote should show the total line amount automatically.”
Implementation:
- Create custom object
Quote__c(or use the standard Quote if appropriate). - Create custom object
Quote_Line_Item__cwith a master-detail field pointing toQuote__c. - On
Quote__c, create a roll-up summary field:Total_Amount__c = SUM(Quote_Line_Item__c.Line_Total__c). - Optional: another roll-up
Line_Count__c = COUNT(Quote_Line_Item__c).
When a user adds, deletes, or changes a line item, the totals on Quote update automatically — no flow, no trigger, no Apex required.
Verified against: Salesforce Help — Master-Detail Relationships and Roll-Up Summary Fields. Last reviewed 2026-05-17.