๐ Connects to: The master-detail choice both legs depend on · One busy parent record creates data skew at scale
Concept
A junction object models many-to-many. It is a custom object with two Master-Detail relationships.
- The first Master-Detail relationship you create is the primary one.
- The junction inherits its look and feel, ownership, and sharing from that primary parent.
- Deleting either master cascade-deletes the junction rows, though undelete behaves differently depending on whether both parents were deleted.
- A junction is also where data about the relationship itself lives: dates, roles, status, or grades on the association.
Nobody picks the primary master by checking a box. It is decided strictly by the order you create the fields: the first Master-Detail relationship you add wins. That is why you cannot see it easily in Setup — you verify it with Workbench or the Metadata API. To swap it, you must convert both relationships down to Lookups and then back to Master-Details in the desired order. Decide the order before you build, not after.
Rule: Many-to-many means one small middle object carrying two Master-Details.
Gain: A real row for the relationship. It holds its own fields (grade, date, quantity) and rolls up to both parent sides.
Price: The junction inherits sharing from both parents. A user needs access to both, so access logic becomes additive and complex.
Limits: Exactly two Master-Details per custom object (a third leg must be a Lookup). The first relationship created is primary, driving look-and-feel and detail sharing. If both masters are deleted, undeleting one will not bring the junction rows back.
Mirror — two lookups instead: Independent sharing and no cascade deletion, but you lose roll-up summary capability on both legs and must manage orphan cleanup manually.
Later: This makes managing Master-Detail slot limits critical. Spend a slot unnecessarily elsewhere, and a junction object becomes impossible.
At volume: Because a junction sits under two parents, it is twice as exposed to parent-record locking contention during parallel operations.
Core Q&A
A: The junction inherits sharing from BOTH parents.
- A user needs at least Read access on both parent records to view the junction record. You configure the required access level on each Master-Detail relationship definition.
- The first relationship created is the primary master. It controls owner inheritance and detail-page association.
- Common Mistake: Creating relationships in the wrong order.
- The only fix is deleting and recreating the relationship, which requires data migration on populated objects. Always choose the primary side deliberately — usually the parent that represents the core business entity.
Follow-ups (Scenario-Based)
A1: Deleting a master record cascade-deletes its junction rows automatically.
- Undeleting that master restores the junction rows. However, if BOTH master records are deleted, undeleting just one parent will NOT restore the junction records.
- Once the second master is deleted, the junction records are permanently purged from the Recycle Bin.
- This asymmetry is critical during data-retention and disaster-recovery architecture reviews.
A2: Evaluate three architectural patterns:
- Option 1: Make the third relationship a required Lookup on the junction. You lose cascade deletion and roll-up capabilities on that third leg, but the association remains queryable.
- Option 2: Split the structure into two separate junction objects chained through an intermediate object.
- Option 3: Re-evaluate whether the third association is actually an attribute (a picklist or reference field) rather than a true relationship parent.
- Reporting Impact: Standard report types traverse limited relationship depth. Deeply normalized models may require Custom Report Types or a flattened reporting object.
Recommended Reading: Custom Metadata Types vs Custom Settings vs Custom Labels