Sub topic 7
Choosing between lookup and master-detail
This chapter assumes you can create custom fields in Object Manager and know what owner, sharing, and record deletion mean in Salesforce. It also assumes you have read the earlier chapters on how each relationship type works. Here you will use that knowledge to make a decision.
The choice matters because it is hard to reverse. Some conversions are blocked by existing data, and a wrong choice can force a data cleanup or a rebuild of sharing rules.
The decision in one sentence
Use master-detail when the child record has no meaning without its parent and should follow the parent's lifecycle and security. Use lookup when the two records are independent and the link is a reference.
Everything else in this chapter explains how to test that sentence against a real requirement.
What differs between the two
| Behavior | Lookup | Master-detail |
|---|---|---|
| Parent value on the child | Optional by default. You can make the field required. | Always required. |
| Deleting the parent | Clears the child's field by default. You can instead block the delete. | Deletes the children too (cascade delete). |
| Child owner | The child has its own Owner field. | No Owner field. The child inherits the parent's owner. |
| Child sharing | Independent of the parent. | Controlled by the parent. |
| Roll-up summary fields | Not available natively. | Available on the master object. |
| Standard object as the child | Allowed. | Not allowed. A standard object can only be the master. |
| Existing records when you create the field | Fine. | You cannot create the field directly on an object that already has records. Create a lookup first, then convert. |
| Self-relationship | Allowed (hierarchical lookup on the same object type). | Not allowed. |
| Reparenting a child | Always allowed. | Off by default. Enable "Allow reparenting" on the field. |
| Limit per object | Many lookup fields. | At most two master-detail fields on a custom object. |
Read the table as a set of consequences that come bundled. You cannot pick master-detail for its roll-ups and also keep a separate owner on the child. Choosing master-detail accepts the whole package.
Questions to ask about the requirement
Work through these questions in order. Most requirements are settled by the first two or three.
- Can the child exist without a parent? If a record is valid with the field empty, such as a Case with no Contact, use lookup. If an empty field would be a data error, master-detail enforces that for you.
- Should deleting the parent delete the child? If a line item should disappear with its order, you want cascade delete. If the child has value on its own, such as a Contact whose Account is removed, you do not.
- Should the child's access follow the parent's? If anyone who can see the parent should see the children, and nobody else should, inherited sharing fits. If the child needs its own owner, its own sharing rules, or a different visibility, you need lookup.
- Do you need a native roll-up summary? If you need declarative SUM, MIN, MAX, or COUNT of children on the parent, master-detail is the straightforward path.
- Is the child a standard object, or does it already hold data? These facts can rule master-detail out before the design discussion starts.
- Could the child be reassigned to a different parent? Master-detail allows it only if you turn on reparenting. That is easy to do, but you should do it deliberately.
Worked examples
Invoice and invoice lines
An Invoice_Line__c record means nothing without its Invoice__c. Deleting an invoice should delete its lines. Finance users who can see an invoice should see all its lines. You also want the invoice to show a total of its line amounts.
Every answer points the same way, so master-detail is the right choice. The roll-up summary field gives you the total with no code.
Contacts and accounts
A Contact can exist without an Account (a private person, or a contact in transition). Contacts can be owned by different people from their Account's owner. Deleting an Account should not silently remove people your team still needs to reach.
This is a lookup. The standard Contact-to-Account relationship is a special case, since it has some extra behavior, but the reasoning is the same.
Projects and tasks with different owners
Suppose each Task__c is assigned to a different team member, and the assignee must be able to edit their task even when they cannot see other tasks on the project. Master-detail would remove the task's owner and tie access to the project, so this fits lookup. If you still want to count open tasks per project, you do that another way.
Replacing a roll-up when you chose lookup
A lookup cannot have a native roll-up summary field. When you need totals on a lookup parent, you have several options: a record-triggered flow, an Apex trigger, a scheduled job, or a managed or open-source roll-up tool. For a one-off report or a small calculation, an aggregate query is enough:
Set<Id> accountIds = new Set<Id>{ '001000000000001AAA' };
List<AggregateResult> totals = [
SELECT AccountId, COUNT(Id) total
FROM Contact
WHERE AccountId IN :accountIds
GROUP BY AccountId
];
for (AggregateResult ar : totals) {
System.debug(ar.get('AccountId') + ' has ' + ar.get('total') + ' contacts');
}The Id above is a placeholder, so replace it with a real Account Id in your org before you run it.
Keep the cost of this in mind. A native roll-up is recalculated by the platform whenever a child changes. A custom roll-up is code or a flow you must write, test, and maintain, and it must handle inserts, updates, deletes, undeletes, and reparenting. If the roll-up is central to the design, that maintenance cost is a real argument for master-detail.
Trade-offs that are easy to miss
Cascade delete cannot be undone selectively
Deleting a master moves its detail records to the Recycle Bin along with it, and undeleting the master restores them. Between those two events, the data is gone from reports and users. If anyone could delete a parent by accident, the blast radius is larger with master-detail. Limit the delete permission on the master object, and treat it as the permission to delete all of its children too.
Sharing is simpler but less flexible
The detail object's sharing setting becomes "Controlled by Parent." You cannot give the detail object its own organization-wide default or its own sharing rules. If a requirement later says "regional managers need to see these child records but not their parents," master-detail cannot express it. You would have to redesign.
Permissions on the master
A master-detail field has a setting, "Allow users to create, edit, and delete detail records only if they have Read access to the master" (writeRequiresMasterRead in metadata). When it is false, which is the default, a user needs Read/Write access to the master record to create or change detail records. When it is true, Read access to the master is enough. Choose this deliberately. The default is the safer one.
Limits shape the model
A custom object can have at most two master-detail fields. If a junction object in a later chapter needs both, it uses up its allowance. Master-detail chains also have a depth limit, and roll-up summary fields only summarize the direct children, not grandchildren.
Lookup flexibility has its own risk
Because a lookup is optional, orphaned children are normal. Reports, validation, and automation must tolerate a blank field. Consider whether to make the lookup required, or to block deletion of the parent. Those options give you part of the integrity of master-detail without its coupling.
Common errors in design reviews
- Using master-detail for "important" relationships. Importance is not a criterion. Lifecycle and security are.
- Forgetting the child's owner disappears. List views, assignment rules, and reports that filter on the child's Owner stop working after you convert to master-detail.
- Making a lookup required and expecting cascade behavior. A required lookup stops blank values, but deleting the parent does not delete the child. Without a block on deletion, the platform may refuse the parent delete or clear the field, depending on the delete setting. Check the field's delete behavior.
- Assuming the choice can be postponed. Data volume and automation built on top of the field make later changes more expensive.
Exercise
A Warranty__c object records coverage for a product the customer bought. Each warranty must belong to exactly one Asset, which is a standard object. Warranties are deleted when the asset is deleted. The warranty needs a total of its Claim__c records. Which relationship type do you use for Warranty__c to Asset, and which for Claim__c to Warranty__c?
Show answer
Use a lookup from Warranty__c to Asset, because a standard object cannot be the detail side of a master-detail relationship, and you can make the lookup required. Use master-detail from Claim__c to Warranty__c, since claims are meaningless without a warranty and the roll-up summary total of claims is available on the master. Deleting an asset will not automatically delete warranties unless you handle that separately, for example with a flow.
Exercise
Your team made a lookup from Task__c to Project__c, and now wants a native SUM of task hours on the project. Tasks have different owners who must keep edit access. Should you convert to master-detail?
Show answer
No. Master-detail would remove the task owner and make access follow the project, which breaks the requirement. Keep the lookup and calculate the sum with a record-triggered flow, an Apex trigger, or a roll-up tool.