What are the defining behavioral characteristics and security impacts of a Master-Detail relationship?
Answer
Basics: Use it when the child cannot exist without the parent, such as invoice line items under an invoice. Salesforce enforces the dependency for you, so no orphan records.
How it works:
- The relationship field on the child is always required; a child cannot be saved without a master.
- The child has no Owner field. Visibility is "Controlled by Parent" in sharing settings, and access follows the master record (plus the user's object permissions on the child).
- Deleting the master cascade-deletes details; undeleting the master restores them.
- Master-detail enables Roll-Up Summary fields on the master.
- Setup: Object Manager > child object > Fields & Relationships > New > Master-Detail Relationship.
Advanced / deep dive: An object can have up to two master-detail relationships; this is how a junction object models many-to-many, and the first (primary) relationship determines the look and feel and the default ownership/sharing behavior of the junction. Reparenting is blocked unless "Allow reparenting" is ticked. Standard objects cannot be the detail side of a custom master-detail (only custom objects can be detail, with some exceptions in managed packages and standard like OpportunityLineItem). Converting lookup to master-detail needs every existing record to have the parent populated, and master-detail to lookup requires removing roll-ups first. Sharing rules and manual sharing cannot be created directly on the detail; share the master instead. Because roll-ups lock the parent, bulk loading many children against one parent invites UNABLE_TO_LOCK_ROW; sort the file by parent in Data Loader and use smaller or serial batches.
Hidden gotchas & must-remember points:
- Maximum two master-detail fields per object, and the field is always required.
- There is no owner on the detail, so you cannot use owner-based sharing rules or queues for it.