Master-detail relationships are a core building block of Salesforce data modeling. They establish a tight parent-child connection between two objects, where the parent (master) directly controls the behavior, security, and lifecycle of the child (detail) record. Building robust applications in Salesforce requires a solid grasp of how these relationships function.
1. What is a Master-Detail Relationship?
In Salesforce, a master-detail relationship links a parent object (master) to a child object (detail). You define this relationship by creating a specialized field on the child object that points to the parent object. Unlike loose lookup relationships, a detail record is strictly dependent on its master record to exist.
2. Key Features and Business Benefits
- Cascade Deletion: If you delete a master record, Salesforce automatically deletes all connected detail records. This prevents orphaned records and maintains data integrity.
- Inherited Security & Sharing: Detail records do not have independent Owner fields or sharing rules. They automatically inherit record visibility, sharing settings, and security permissions from their master record.
- Roll-Up Summary Fields: You can create native roll-up summary fields on the master object to calculate real-time metrics—such as
SUM,COUNT,MIN, orMAX—across all connected child records.
3. How to Create a Master-Detail Relationship
Follow these steps in Salesforce to establish a master-detail link between two objects:
- Navigate to Setup → Object Manager.
- Select the Child (Detail) Object where you want the relationship field to reside.
- Click Fields & Relationships → New.
- Choose Master-Detail Relationship as the Data Type and click Next.
- Select the Parent (Master) Object from the drop-down menu.
- Define field properties (such as Field Label, Field Name, and optional reparenting settings) and save your changes.
4. Important Considerations and Limitations
- 1-to-Many Architecture: One master record can link to many detail records, but each detail record connects to exactly one master.
- Custom Object Limits: A custom object can have a maximum of two Master-Detail relationship fields.
- Strict Conversion Rules: You cannot convert a Lookup relationship into a Master-Detail relationship unless every existing child record already contains a populated parent reference.
- Detail Field Requirement: The Master-Detail relationship field is always mandatory on the child object page layout.
5. Real-World Use Cases
Here are two classic examples of master-detail relationships in enterprise business models:
- Order and Line Items: An
Order__crecord acts as the master, controlling overall payment status and ownership. IndividualOrder_Item__cdetail records store products, quantities, and prices. Deleting the order removes its line items, and a roll-up summary calculates the total order amount. - Expense Report and Expense Line Items: An
Expense_Report__crecord acts as the master, whileExpense_Item__cdetail records log individual receipts. The total claimed amount automatically rolls up to the master report.
- Parent Control: Master controls detail record ownership, sharing, and security.
- Deletion Logic: Cascade delete automatically cleans up child records when the parent is removed.
- Aggregation Power: Unlocks native Roll-Up Summary fields on the parent object.
- Field Limits: Maximum of 2 Master-Detail relationships per custom object.
Conclusion
Master-detail relationships are essential for building secure, scalable data structures in Salesforce. By mastering how they enforce parent-child dependency, inherit security, and enable roll-up summaries, you can design cleaner databases that safeguard data integrity and streamline operations.