3.2 Relationship Types & Implications
Key Takeaways
- Lookup relationships are loosely coupled; master-detail is tightly coupled with cascade delete, inherited sharing, and roll-up summaries on the master
- Many-to-many requires a junction object with two master-detail (or sometimes lookup) relationships to the parents
- Hierarchical relationships are a special self-lookup on User; external and indirect lookups connect to external objects
- Relationship choice drives record access, ownership, reparenting, related lists, and parent-child SOQL shape
- Reparenting is allowed on lookups by default and is controlled for master-detail via Allow reparenting
3.2 Relationship Types & Implications
Quick Answer: Choose lookup for optional or loosely coupled parents, master-detail when the child cannot exist without the parent and you need cascade delete, inherited security, and roll-up summaries, and a junction object for many-to-many. External and indirect lookups reach external objects; hierarchical is a special self-relationship on User.
Relationship design is one of the highest-yield data modeling topics on Platform Developer I. The same business “link” can be modeled several ways; the platform enforces very different behavior for each.
Lookup Relationships
A lookup creates an optional (or optionally required) foreign-key style link from a child to a parent.
Characteristics:
- Child can usually exist without a parent if the lookup is not marked required
- Parent and child can have independent owners and sharing
- Deleting the parent does not cascade-delete children by default (you can configure clear vs restrict-style behaviors depending on field settings and object type; know the exam framing: lookups are loosely coupled)
- No roll-up summary fields on pure lookup parents (use Flow, Apex, or declarative workarounds)
- Related lists appear on the parent; the child stores the parent Id in a field ending in
__c(custom) with relationship navigation via__r
When to use: Related but independent records (for example, optional related Account on a custom Project, or linking Case to a custom Asset when the asset is not a strict parent).
Master-Detail Relationships
A master-detail relationship tightly couples child to parent.
Characteristics:
- Child requires a parent (detail cannot be orphaned)
- Cascade delete: deleting the master deletes detail records
- Inherited sharing: detail access is controlled by the master’s sharing (detail does not have independent OWD in the usual master-detail sense)
- Detail records typically do not have their own owner independent of the master (ownership follows the master model)
- Master can define roll-up summary fields (COUNT, SUM, MIN, MAX) over detail records
- A custom object can have up to two master-detail relationships (the foundation of many junction designs)
When to use: True parent-child lifecycles—Invoice Lines under Invoice, Expense Items under Expense Report—where lines should not survive the parent and should roll up totals.
| Dimension | Lookup | Master-Detail |
|---|---|---|
| Coupling | Loose | Tight |
| Parent required | Optional unless marked required | Always required |
| Cascade delete | Not the default tight cascade model | Yes—detail deleted with master |
| Security | Independent | Inherits from master |
| Roll-up summaries | No (native) | Yes on master |
| Ownership | Child can own independently | Controlled with master |
Many-to-Many (Junction Objects)
Salesforce has no first-class “M:N field.” You model many-to-many with a junction object that has two relationships to the parent objects—classically two master-detail relationships (for example, Job_Application__c junction between Candidate__c and Position__c).
Implications:
- Each junction row represents one association pair (plus association attributes: status, applied date)
- With two master-details, junction sharing and cascade behavior follow master-detail rules from both parents (understand deletion impact)
- Related lists on each parent show related counterparts through the junction
- SOQL often queries the junction and navigates both
__rparents, or uses subqueries from either parent
Sometimes architects use lookup-based junctions when independent ownership or optional parents are required—but then you lose native roll-ups and cascade semantics. Exam scenarios that stress “must be deleted with parent” and “roll up count of related X” point to master-detail junctions.
Hierarchical Relationships
A hierarchical relationship is a special lookup limited to the User object (self-relationship). It models manager hierarchies and similar user trees without using a generic self-lookup pattern available on all objects. For custom objects, self-relationships are ordinary lookups to the same object (for example, parent Account uses the standard Account hierarchy; custom Team__c might look up another Team__c).
External Lookup and Indirect Lookup
When Salesforce Connect exposes external objects (data lives outside Salesforce):
- External lookup: Child (Salesforce or external) relates to a parent external object using the external object’s external ID-style key
- Indirect lookup: External child object relates to a standard/custom Salesforce parent by matching an External ID field on the parent
These relationships power hybrid architectures. They do not behave like in-org master-detail for cascade delete and roll-ups; treat external data as loosely coupled and latency-sensitive. Exam items often test whether you recognize that external/indirect lookups are the correct link type when one side is an external object.
Record Access, UI, and Related Lists
Relationship type shapes the user experience:
- Related lists on parent layouts show child records; master-detail and lookup both support related lists, but security may hide children the user cannot see
- Master-detail children appear only when the user can access the master (inherited model)
- Lookup children may be visible based on their own sharing even if parent visibility differs (and vice versa), which can surprise admins
- Detail pages show lookup fields as clickable links to parents
Apex and SOQL Implications
- Child-to-parent:
SELECT Name, Account__r.Name FROM Invoice__c - Parent-to-child subquery:
SELECT Name, (SELECT Amount__c FROM Invoice_Lines__r) FROM Invoice__c - Relationship API names (plural child relationship names) are set when the relationship field is created—wrong names break subqueries
- Master-detail cascades mean Apex deletes on parents can remove large child sets—watch governor limits and recursive triggers
- Inserting detail records requires parent Id; order of insert in tests and loaders matters
Reparenting Rules
Reparenting means changing a child’s parent pointer after insert.
- Lookup: Generally allowed (unless the field is restricted); child can move between parents
- Master-detail: Reparenting is disabled by default on the relationship; admins can enable Allow reparenting on the master-detail field when the business must move details between masters
Exam scenarios that say “child must always stay with the original parent” align with master-detail without reparenting; “reassign line items to another order” needs lookup or master-detail with reparenting enabled.
Choosing Quickly Under Exam Pressure
- Optional parent or independent security → lookup
- Required parent, cascade delete, roll-ups, inherit sharing → master-detail
- Many parents to many children → junction object
- User manager chain → hierarchical (User)
- Parent or child is external object → external / indirect lookup
Get the relationship wrong and every later choice—roll-ups, sharing, Apex, imports—gets harder. Get it right and the platform does much of the work for you.
Which relationship type natively supports roll-up summary fields on the parent?
How do you model a many-to-many relationship between Position and Candidate so each association can store an applied date?
An admin needs detail records to be deleted automatically when the parent is deleted, and detail access should follow the parent. Which relationship should they choose?