Master Detail Relationships Enable The Platform
How master detail and look up relationships work, a central piece of the Salesforce platform.
- 6 min read
Understanding Master-Detail and Lookup Relationships in Salesforce
Salesforce provides two primary types of relationship fields that connect objects: Master-Detail relationships and Lookup relationships. Both are essential for organizing and managing data, but they serve different purposes and have distinct characteristics. Understanding when to use each type is crucial for building effective Salesforce data models.
Master-Detail Relationships: Tightly Coupled Connections
Master-Detail relationships create a tightly coupled connection between two objects where the Detail (child) record is completely dependent on the Master (parent) record. The Master object controls the behavior, security, and lifecycle of the Detail records.
Key Characteristics:
- Cascade Delete: When the Master record is deleted, all Detail records are automatically deleted
- Required Relationship: Detail records cannot exist without a Master record
- Security Inheritance: Detail records inherit sharing and security settings from the Master
- Roll-Up Summary Fields: You can create roll-up summary fields on the Master to aggregate data from Detail records
- Ownership: Detail records don’t have their own owner field - they inherit ownership from the Master
Lookup Relationships: Flexible Connections
Lookup relationships create a more flexible connection between objects where records can exist independently. The child record can optionally reference a parent record, but it’s not required.
Key Characteristics:
- Independent Records: Child records can exist without a parent
- No Cascade Delete: Deleting the parent doesn’t automatically delete child records
- Own Ownership: Child records have their own owner field
- Independent Security: Child records have their own sharing and security settings
- No Roll-Up Summaries: Cannot create roll-up summary fields (unless converted to Master-Detail)
Real-World Use Cases
Use Case 1: Order and Order Line Items (Master-Detail)
Scenario: An e-commerce company needs to track orders and their line items.
Relationship: Order (Master) → Order Line Items (Detail)
Why Master-Detail:
- Line items have no meaning without an order
- Deleting an order should delete all line items
- Need to calculate total order value (roll-up summary)
- Line items share the order’s security settings
Custom Fields on Order Line Item:
- Product (Lookup to Product)
- Quantity (Number)
- Unit Price (Currency)
- Line Total (Formula: Quantity × Unit Price)
For more on creating and using custom fields, see our guide on custom fields in Salesforce.
Roll-Up Summary on Order:
- Total Order Value (Sum of Line Total)
- Number of Line Items (Count)
Business Impact:
- Accurate order totals automatically calculated
- Complete order deletion when needed
- Simplified reporting on order values
Use Case 2: Project and Tasks (Lookup)
Scenario: A consulting company tracks projects and related tasks.
Relationship: Project (Parent) → Tasks (Child) - Lookup
Why Lookup:
- Tasks might be created before a project is finalized
- Tasks might be reassigned to different projects
- Tasks have their own owners and due dates
- Need flexibility to manage tasks independently
Custom Fields on Task:
- Project (Lookup to Project)
- Assigned To (Lookup to User)
- Due Date (Date)
- Status (Picklist)
- Hours Worked (Number)
Business Impact:
- Flexibility to manage tasks across projects
- Tasks can exist independently if project changes
- Better resource allocation tracking
Use Case 3: Account and Contacts (Standard Lookup)
Scenario: Standard Salesforce Account-Contact relationship.
Why Lookup (not Master-Detail):
- Contacts might need to exist without an account (B2C scenarios)
- Contacts have their own owners and security
- Need flexibility for contact management
However: Salesforce allows converting this to Master-Detail in some scenarios for B2B use cases where contacts must belong to accounts.
Use Case 4: Campaign and Campaign Members (Master-Detail)
Scenario: Marketing team tracks campaigns and campaign members.
Relationship: Campaign (Master) → Campaign Members (Detail)
Why Master-Detail:
- Campaign members only exist in context of a campaign
- Deleting a campaign should remove all members
- Need to roll up response rates and engagement metrics
- Members inherit campaign security settings
Roll-Up Summaries on Campaign:
- Total Members (Count)
- Responded Members (Count with criteria)
- Response Rate (Formula: Responded / Total)
Converting Master-Detail to Lookup
Sometimes you need to convert a Master-Detail relationship to Lookup for more flexibility. This process requires careful planning:
Steps to Convert:
- Identify Roll-Up Summary Fields: Find all roll-up summary fields on the Master object that reference this relationship
- Replace or Remove: Use Process Builder, Flow, or Apex to recreate the calculations, or remove if no longer needed
- Back Up Data: Export all Detail records to ensure data safety
- Delete the Field: Delete the Master-Detail relationship field
- Create Lookup Field: Create a new Lookup field with the same name or a new name
- Restore Relationships: Use Data Loader or other tools to repopulate the relationships using your backup
Real-World Scenario:
A company initially created a Master-Detail relationship between Account and Custom Object “Service Contracts.” Later, they realized:
- Service contracts might need to exist independently during transitions
- Contracts might be reassigned between accounts
- They need more flexibility in contract management
Solution: Converted to Lookup relationship, allowing contracts to exist independently and be reassigned as needed.
Best Practices for Choosing Relationship Types
Use Master-Detail When:
- Child records have no meaning without the parent
- You need cascade delete functionality
- You need roll-up summary fields
- Child records should inherit parent security
- The relationship is permanent and unlikely to change
Examples:
- Invoice → Invoice Line Items
- Quote → Quote Line Items
- Project → Project Tasks (if tasks are project-specific)
- Campaign → Campaign Members
Use Lookup When:
- Child records can exist independently
- You need flexibility to reassign relationships
- Child records need their own security settings
- The relationship is optional
- You might need to break the relationship
Examples:
- Account → Opportunities (standard - can be converted to Master-Detail for some orgs)
- Contact → Cases (standard)
- Custom Object → Tasks
- Project → Related Documents
Common Patterns and Examples
Pattern 1: Hierarchical Data
Account Hierarchy:
- Parent Account (Lookup to Account)
- Child Accounts (Master-Detail to Account for some scenarios, or Lookup)
Use Case: Enterprise accounts with subsidiaries
Pattern 2: Transactional Data
Order Management:
- Order (Master)
- Order Line Items (Detail)
- Payments (Detail or Lookup, depending on requirements)
Pattern 3: Project Management
Project Structure:
- Project (Master)
- Project Phases (Detail)
- Phase Tasks (Detail of Phase, or Lookup to Project)
Resources
- Salesforce Help: Master-Detail Relationships
- Salesforce Help: Lookup Relationships
- Trailhead: Create Relationships Between Objects
- Best Practices: Relationship Field Considerations
Conclusion
Master-Detail and Lookup relationships are fundamental to building effective Salesforce data models. Master-Detail relationships provide tight coupling, cascade delete, and roll-up summary capabilities, making them ideal for dependent records. Lookup relationships offer flexibility and independence, perfect for optional or reassignable connections.
Understanding when to use each type, and how to convert between them when needed, is essential for building scalable, maintainable Salesforce solutions. By choosing the right relationship type for your use case, you can create data models that support your business processes while maintaining data integrity and flexibility.
Choose wisely: the right relationship type can make or break your Salesforce implementation.
