Master Detail Relationship in Salesforce Featured Image

If you’re learning Salesforce administration, understanding the master detail relationship is non-negotiable. It’s one of the most powerful data modeling concepts in the Salesforce platform — and one that every Salesforce Admin is expected to master.

A master detail relationship in Salesforce is a parent-child relationship between two objects where the master (parent) object controls certain behaviors of the detail (child) object. This is a tightly coupled relationship — meaning the child record cannot exist independently of the parent.

In simpler terms:

  • The Master object is the parent.
  • The Detail object is the child.
  • Delete the parent → the child records are automatically deleted too.

This relationship is fundamentally different from how a lookup relationship works, and choosing between them is a critical decision in Salesforce data architecture.

How Does a Master Detail Relationship Work?

When you create a master detail relationship, Salesforce establishes a tight bond between the two objects. Here’s what happens under the hood:

  1. A required lookup field is created on the detail (child) object that points to the master (parent) object.
  2. The ownership and sharing of the detail record are determined by the master record — the detail record inherits the master’s sharing rules.
  3. The detail record cannot exist without a master record — the relationship field is mandatory.
  4. When a master record is deleted, all related detail records are automatically deleted (cascade delete).
  5. If a master record is undeleted, all related detail records are restored.

This behavior makes the master detail relationship ideal for scenarios where the child data is completely dependent on the parent.

Key Characteristics of Master Detail Relationship

Here are the defining features of a master detail relationship in Salesforce:

1. Required Relationship Field

The master-detail field on the child object is always required. You cannot save a detail record without linking it to a master record.

2. Cascade Delete

When a master record is deleted, all its associated detail records are automatically deleted. This maintains data integrity.

3. Ownership and Sharing Inherited from Master

The child (detail) record does not have its own owner field. Instead, it inherits the owner and sharing settings from the master record. This simplifies security management.

4. Roll-Up Summary Fields

This is arguably the most powerful feature. Master objects can have Roll-Up Summary fields that automatically calculate values (COUNT, SUM, MIN, MAX) based on the detail records. You cannot create roll-up summary fields with a standard Lookup relationship.

5. Up to Two Master-Detail Relationships Per Object

A custom object can have a maximum of two master-detail relationships, which allows for junction objects (many-to-many relationships).

6. Standard Objects Cannot Be on the Detail Side

Standard Salesforce objects (like Account, Contact, Opportunity) cannot be on the detail side of a master-detail relationship. Custom objects, however, can be either master or detail.

Master Detail Relationship vs. Lookup Relationship

This is the comparison every Salesforce Admin must know cold — and it’s a favorite topic in the Salesforce Admin Certification exam.

Feature Master Detail Relationship Lookup Relationship
Required field Yes — always required No — optional
Cascade delete Yes — child deleted with parent No — child remains
Ownership Inherited from master Child has its own owner
Sharing rules Inherited from master Independent
Roll-Up Summary Supported Not supported
Standard object on detail side Not allowed Allowed
Max per object 2 40
Relationship type Tight coupling Loose coupling
Child without parent Not possible Possible

The Key Takeaway

Use master detail when the child record is meaningless without the parent. Use lookup when the relationship is optional or the child can exist independently.

When to Use Master Detail Relationship

You should use a master detail relationship when:

When to Use Master Detail Relationship
  • The child record is completely dependent on the parent. For example, an Invoice Line Item cannot exist without an Invoice.
  • You need Roll-Up Summary fields to aggregate data from the child to the parent (e.g., total revenue, count of items).
  • You want the parent to control security and sharing of the child records automatically.
  • Cascade delete is acceptable — when deleting the parent should automatically clean up related child records.
  • You are building a junction object for a many-to-many relationship (requires two master-detail relationships).

Creating a Master Detail Relationship in Salesforce

Here’s a step-by-step walkthrough for creating a master detail relationship in Salesforce:

Step 1: Go to Setup → Object Manager.

Step 2: Select the child (detail) object where you want to add the relationship field.

Step 3: Navigate to Fields & Relationships → Click New.

Step 4: Select Master-Detail Relationship as the field type → Click Next.

Step 5: In the “Related To” field, select the parent (master) object → Click Next.

Step 6: Configure the field label, field name, and other settings.

Step 7: Set field-level security (who can see this field) → Click Next.

Step 8: Choose which page layouts to add the field to → Click Save.

That’s it! The relationship is now created, and the detail records are linked to the master.

Pro Tip: If you’re converting a Lookup relationship to a Master-Detail relationship, all existing lookup fields must have a value first — no nulls allowed.

Roll-Up Summary Fields

One of the most useful features unlocked by a master detail relationship is the Roll-Up Summary field. This allows the master (parent) object to display aggregated data from its related detail records.

Supported Roll-Up Types

Function Description
COUNT Counts the number of related child records
SUM Adds up the values in a numeric field on child records
MIN Displays the minimum value from child records
MAX Displays the maximum value from child records

Real Example

Imagine you have a custom object called Project (master) with related Project Tasks (detail). You can create a Roll-Up Summary field on the Project object to:

  • COUNT the total number of tasks
  • SUM the total hours logged across all tasks
  • MIN the earliest task due date
  • MAX the latest task due date

This eliminates the need for manual data entry or complex automation.

Real-World Examples of Master Detail Relationship

Example 1: Order and Order Line Items

  • Master: Order
  • Detail: Order Line Item
  • Each Order Line Item is meaningless without an Order. Deleting an Order should remove all its line items. Roll-Up Summary fields on Order can calculate total order value.

Example 2: Account and Contacts (Custom Scenario)

  • Master: Account (custom)
  • Detail: Contact (custom)
  • In custom-built applications where contacts are entirely dependent on accounts.

Example 3: Invoice and Invoice Items

  • Master: Invoice
  • Detail: Invoice Line Item
  • Classic example of tight dependency. Total invoice amount can be calculated via Roll-Up Summary.

Example 4: Campaign and Campaign Members (Junction Object)

  • Many-to-many relationships in Salesforce use junction objects with two master-detail relationships.
  • Example: A “Course Enrollment” object has master-detail relationships to both “Student” and “Course.

Limitations and Considerations

While powerful, the master detail relationship has important limitations to keep in mind:

  • Maximum of 2 master-detail relationships per custom object.
  • Standard objects cannot be on the detail side — only custom objects.
  • Converting a lookup to master-detail requires all existing records to have a populated lookup field (no blank/null values allowed).
  • Roll-Up Summary fields cannot use cross-filter criteria in some configurations.
  • Records in a master-detail relationship cannot be easily reparented (changing the master) unless you explicitly allow reparenting in the field settings.
  • You cannot create a master-detail relationship if the detail object already has data and existing records don’t have a value for the master field.

Best Practices for Master Detail Relationships

Follow these best practices to get the most out of master detail relationships in your Salesforce org:

1. Plan your data model before building. Decide upfront whether the relationship should be master-detail or lookup. Changing it later can be complex and data-intensive.

2. Use Roll-Up Summary fields to reduce automation. Wherever you need to calculate totals, counts, or extremes from child records, Roll-Up Summary fields are more efficient than triggers or flows.

3. Enable reparenting thoughtfully. By default, master-detail allows reparenting (moving a child to a different parent). Disable this if your business logic requires strict parent-child permanence.

4. Think carefully about cascade delete. If deleting a parent record should NOT delete children, use a Lookup relationship instead.

5. Use junction objects for many-to-many relationships. If two objects need a many-to-many relationship, create a junction object with two master-detail relationships pointing to each object.

6. Document your relationships. Use Salesforce’s Schema Builder to visually map your object relationships and keep documentation updated for your team.

Frequently Asked Questions

What is the master detail relationship in Salesforce?

A master detail relationship is a parent-child relationship between two Salesforce objects where the child (detail) record is tightly dependent on the parent (master) record. The child inherits ownership and sharing from the parent, and deleting the parent cascades to delete all related child records.

How many master detail relationships can an object have?

A custom object can have a maximum of two master-detail relationships. This limit allows junction objects to be built for many-to-many data scenarios.

Can a standard object be on the detail side of a master-detail relationship?

No. Standard Salesforce objects (like Account, Contact, Opportunity) cannot be placed on the detail side. Only custom objects can serve as the detail in a master-detail relationship.

What is the difference between master detail and lookup relationship in Salesforce?

The key differences are: master-detail requires the relationship field (lookup is optional), master-detail cascades deletes (lookup does not), master-detail inherits ownership (lookup has independent ownership), and only master-detail supports Roll-Up Summary fields.

Can I convert a lookup relationship to a master-detail relationship?

No. Standard Salesforce objects (like Account, Contact, Opportunity) cannot be placed on the detail side. Only custom objects can serve as the detail in a master-detail relationship.

What happens if I delete a master record?

All related detail records are automatically and permanently deleted (cascade delete). This cannot be undone unless the master record is undeleted, which also restores the child records.

Conclusion

The master detail relationship is one of the cornerstone concepts in Salesforce data modeling. From enabling Roll-Up Summary fields to automatically managing data security and cascade deletes, it gives admins powerful tools to build clean, efficient, and scalable data architectures.

Whether you’re building custom apps, designing automation, or architecting enterprise data models, a solid understanding of master detail relationships will make you a far more effective Salesforce professional.

Ready to Master Salesforce Admin Concepts Like This?

If this guide helped you understand master detail relationships, imagine what a structured, hands-on Salesforce Admin certification course could do for your career.

This course is designed specifically for aspiring Salesforce Administrators and covers:

  • Object relationships (Master-Detail, Lookup, Hierarchical, and more)
  • Data modeling and Salesforce architecture fundamentals
  • Roll-Up Summary fields, validation rules, and automation
  • Security model — profiles, roles, OWD, and sharing rules
  • Reports, dashboards, and analytics
  • Full preparation for the Salesforce Certified Administrator exam

Have questions about Salesforce relationships or the certification exam? Drop them in the comments below!

Share:

Recent Posts