04.01.03 — Relationship Testing: Lookup vs Master-Detail
💡 The Problem: Relationships Define Behavior
In Salesforce, relationships are not just links between objects.
They are behavioral switches that define how data behaves when records are deleted, who can see related records, and what kind of automation is possible.
The chosen relationship type directly affects:
- data integrity
- security and sharing
- automation behavior
- performance and platform limits
From a QA perspective, this makes relationship testing one of the highest-risk areas in the data model.
⚙️ The Two Relationship Types from a QA Perspective
Salesforce provides two primary relationship types:
- Master–Detail
- Lookup
Each one enforces a very different set of rules that must be tested explicitly.
1. Data Integrity and Deletion Behavior
The most visible difference between relationship types appears when the parent record is deleted.
| Relationship Type | Integrity Model | Deletion Behavior to Test |
|---|---|---|
| Master–Detail | Hard integrity | Deleting the parent must automatically delete all child records |
| Lookup | Soft integrity | Deleting the parent must leave child records intact and nullify the lookup field |
Master–Detail: Cascading Delete
In a Master–Detail relationship:
- child records cannot exist without a parent
- deleting the master record triggers an immediate cascade delete
QA focus:
- delete the master record
- verify that all related detail records are deleted
- confirm they are not recoverable as independent records
Lookup: Orphan Records
In a Lookup relationship:
- child records are independent
- deleting the parent sets the lookup field to
null
QA focus:
- delete the parent record
- verify the child record still exists
- verify the lookup field is cleared automatically
Important edge case:
If the Lookup field is marked as Required at schema level, deleting the parent will still nullify the field.
The failure appears on the next save of the child record, not during deletion.
2. Security and Sharing Inheritance
Relationships have a major impact on who can see what.
Master–Detail: Inherited Security
In Master–Detail:
- the child record inherits all security from the master
- object-level sharing on the detail object is ignored
QA focus:
- log in as a user without access to the detail object
- grant access to the master record
- verify the user can still see the detail records
This behavior often surprises teams and causes production access leaks if not tested.
Lookup: Independent Security
In Lookup relationships:
- security is evaluated independently for parent and child
- sharing rules and OWD apply separately
QA focus:
- verify that a user may see a child record without seeing the parent
- validate that sharing rules behave consistently for both objects
3. Automation and Roll-Up Summary Fields
Roll-Up Summary Fields are only available in Master–Detail relationships.
They introduce indirect behavior that must be tested carefully.
QA focus:
- Create a new child record → verify the roll-up recalculates immediately.
- Update a qualifying child record → verify recalculation.
- Delete the last child record → verify roll-up resets correctly.
- Update non-relevant fields → verify no unnecessary recalculation occurs.
Large numbers of child records increase the risk of:
- governor limit breaches
- performance degradation
- delayed recalculations
🚀 Practical QA Techniques
Testing Relationship Limits
Relationships influence how deeply Salesforce must traverse data.
High-risk scenarios to test:
- deep lookup chains (A → B → C → D)
- automation accessing data across multiple levels
- bulk operations triggering roll-up recalculations
These scenarios often expose hidden SOQL query limit issues.
---
Reparenting in Master–Detail
Changing the master record on a detail record triggers:
- roll-up recalculation on both old and new parents
- security re-evaluation
- automation side effects
QA focus:
- test reparenting explicitly
- verify data consistency before and after the change
- confirm no orphaned or duplicated roll-up values appear
Custom Logic That Mimics Relationships
Sometimes teams use:
- Lookup relationships
- Validation Rules or Apex
to simulate Master–Detail behavior
QA focus:
- identify custom enforcement logic
- attempt parent deletion
- verify the correct custom error message is shown
- ensure behavior is consistent across UI and API
✅ Summary: Relationship Type Is a Design Decision
Choosing between Lookup and Master–Detail is not just a modeling decision — it is a testing strategy decision.
- Master–Detail requires rigorous testing of cascading deletes, inherited security, and roll-up recalculations.
- Lookup requires careful testing of orphan records, sharing rules, and independent access paths.
Understanding these implications allows QA to:
- anticipate failure modes
- design focused test cases
- prevent data integrity and security issues before they reach production
In Salesforce, relationships don’t just connect data — they define how the system behaves.