A master-detail relationship is a tightly coupled parent-child link between two objects in Salesforce, where the master (parent) controls key behaviors of the detail (child). A detail record cannot exist on its own: it has no owner of its own, inherits the master's sharing and security, and is deleted automatically when the master is deleted (cascade delete).
This guide covers what a master-detail relationship is, how it differs from a lookup and the other relationship types, the rules and gotchas to watch for, and the exact steps to create one in the current (2026) Salesforce Setup using Object Manager.
Master-detail vs. lookup (and other relationship types)
Salesforce offers several ways to relate records, and picking the right one up front saves painful data migrations later.
| Behavior | Master-detail | Lookup |
|---|---|---|
| Required on the child? | Yes, always required | Optional by default |
| Child has its own owner? | No - inherits the master | Yes |
| Sharing and security | Inherited from the master | Independent |
| Deleting the parent | Cascade-deletes the children | Children are kept |
| Roll-up summary on parent | Supported | Not supported natively |
| Reparent the child | Only if reparenting is allowed | Always |
Note: native roll-up summary fields require a master-detail relationship; teams that need to roll up a lookup use Flow or a third-party tool instead.
Other relationship patterns you may meet:
- Lookup - a loose reference; the child stands on its own.
- Hierarchical - a special lookup available only on the User object, used for manager chains.
- Many-to-many (junction object) - two master-detail fields on a junction object (see below).
- External / indirect lookup - link a record to an external object (Salesforce Connect / OData) instead of a local record.
If you only need to pair one record with exactly one other, see creating a one-to-one relationship in Salesforce.
Key behaviors and rules
- The detail record always requires a master. The relationship field is required on the detail page layout and cannot be left blank.
- No owner on the detail record. The child has no Owner field; it inherits ownership, sharing, and record-level security from its master.
- Cascade delete. Deleting a master deletes all of its detail records (and their details, down the chain).
- Roll-up summary fields can be created only on the master, aggregating its detail records. They support COUNT, SUM, MIN, and MAX - there is no built-in AVG, so calculate it as SUM divided by COUNT.
- Up to two master-detail fields per object. An object can be the detail side of at most two master-detail relationships - exactly what enables the junction-object (many-to-many) pattern.
- Multilevel master-detail. Relationships can be chained up to three custom levels deep.
- Reparenting is off by default. Enable Allow reparenting on the field if users need to move a child to a different master.
For how inherited access plays out at the field level, review how to set field-level security in Salesforce.
Step-by-step: create a master-detail relationship
You create the relationship from the detail (child) object, pointing it at the master (parent). For example, to make Invoice Line a detail of Invoice, you add the field on Invoice Line.
- From Setup, open Object Manager and select the detail (child) object.
- Click Fields & Relationships, then New.
- Choose Master-Detail Relationship as the data type and click Next.
- In Related To, pick the master (parent) object, then click Next.
- Enter the Field Label and Field Name (the API name auto-fills), add optional help text, then click Next.
- Set the Sharing Setting (the access on the master needed to create or edit a detail) and, if required, tick Allow reparenting. Click Next.
- Set field-level security for the relationship field per profile, then click Next.
- Choose the page layouts that should display the field, then click Next.
- Add a related list to the master's page layouts so child records are visible from the parent, then click Save.
New detail records will now require a master, and you can add roll-up summary fields on the parent.
Prefer a visual approach? You can also model relationships in Schema Builder.
Many-to-many: the junction object pattern
Salesforce has no native many-to-many field. Instead you build a junction object - a custom object that sits between the two objects you want to relate and holds two master-detail relationships.
Example: relate Candidate and Job Posting through a Job Application junction object.
- Create the junction custom object (for example, Job Application).
- Add the first master-detail field, pointing to one parent such as Candidate. This first relationship is the primary one - it controls the junction record's owner, sharing, division, and look-and-feel.
- Add the second master-detail field, pointing to the other parent such as Job Posting. This is the secondary relationship.
Each candidate can now relate to many job postings and vice versa, with the junction record capturing the details of each pairing, such as status and applied date.
Common gotchas
- You usually cannot add a required master-detail field to an object that already has records - existing rows would be orphaned with no master. Add a lookup first, populate it on every record, then convert.
- Converting a lookup to master-detail: every child record must have the lookup populated (no blanks). After converting, re-test your custom reports - the underlying report type can change and break existing reports.
- Standard objects cannot be the detail side of a master-detail relationship. A custom object can be the detail of a standard object, but a standard object (Account, Contact, and so on) can never be the child.
- Converting master-detail back to lookup is only allowed when no roll-up summary fields reference the relationship.
- Mind the limits on cascade deletes and roll-up recalculation in large data volumes - see Salesforce governor limits.
Roll-up summaries vs. Apex
On a master-detail, roll-up summaries are point-and-click - no code. They live on the master and aggregate detail records (COUNT, SUM, MIN, MAX).
For a lookup relationship, where native roll-ups are not available, roll up with a Flow or a short Apex trigger that uses a SOQL aggregate query:
// Sum child Amount__c onto the parent for a LOOKUP relationship
Map<Id, Decimal> totals = new Map<Id, Decimal>();
for (AggregateResult ar : [
SELECT Parent__c pid, SUM(Amount__c) total
FROM Child__c
WHERE Parent__c IN :parentIds
GROUP BY Parent__c
]) {
totals.put((Id) ar.get('pid'), (Decimal) ar.get('total'));
}
List<Parent__c> updates = new List<Parent__c>();
for (Id pid : totals.keySet()) {
updates.add(new Parent__c(Id = pid, Total__c = totals.get(pid)));
}
update updates;
Need help modelling a complex data structure or migrating relationships safely? Our Salesforce team does this work every day.
Frequently Asked Questions
What is the difference between a master-detail and a lookup relationship?
A master-detail tightly couples the records: the detail is required, has no owner, inherits the master's sharing and security, is cascade-deleted with the master, and lets the master hold roll-up summary fields. A lookup is a loose link: the child is independent, optional by default, keeps its own owner and sharing, and survives if the parent is deleted.
Can I convert a lookup relationship into a master-detail?
Yes, as long as every child record already has the lookup field populated with no blanks. Add the lookup, backfill all records, then change the field type to Master-Detail. Afterwards, re-test your custom reports, because the underlying report type can change.
How many master-detail relationships can one object have?
An object can be the detail side of up to two master-detail relationships, and you can chain them up to three custom levels deep. Two master-detail fields on a single junction object is what creates a many-to-many relationship.
Can a standard object be the detail side of a master-detail relationship?
No. Standard objects such as Account, Contact, and Opportunity cannot be the detail (child). A custom object can be the detail of a standard object, but never the other way around.
Why can't I create a master-detail field on an object that already has records?
The relationship field is required on every detail record, so existing rows would have no master and the field cannot be saved. Create a lookup first, populate it on all records, then convert the lookup to master-detail.
What aggregations can a roll-up summary field perform?
On the master object, roll-up summaries support COUNT, SUM, MIN, and MAX over the detail records. There is no native AVG - compute it as SUM divided by COUNT, or use a Flow or Apex for anything more complex.