Home SalesforceInterview Question Lookup vs Master-Detail Relationship in Salesforce

Lookup vs Master-Detail Relationship in Salesforce

by Dhanik Lal Sahni
Lookup Vs Master Detail Relationship

Lookup relationships and master-detail relationships are used to establish relationships between objects (or tables) in the Salesforce database. Both relationships differ in terms of behaviour, functionality, and impact on data management. As both are very important for data modelling, we should know where should use Lookup and Master-Detail Relationship. Let us see the differences between Lookup and Master-Detail Relationship using the below parameters

  1. Relationship type
  2. Ownership and Cascade Deletion
  3. Roll-up Summary Fields
  4. Sharing and Security
  5. Field Dependency

You can check our other post Types of Relationships in Salesforce to understand relationships supported by Salesforce.

1. Relationship Type

Lookup Relationship

A lookup connection is a loosely connected relationship in which one object refers to another. It enables one object (child) to link to another object (parent) without requiring the parent record to be present. A single-parent record can have multiple child records linked to it, and the child record can exist independently of the parent record.

Master-Detail Relationship

A master-detail relationship is a tightly coupled relationship where one object (detail) is considered subordinate to another object (master). The master record owns the detail record and it cannot exist without it. A master-detail relationship suggests that the two objects are highly dependent on one another.

2. Ownership and Cascade Deletion

Lookup Relationship

Child records in a lookup relationship are not owned by the parent record. When a parent record is deleted, the child record is not affected, and the lookup field on the child record is left empty.

Master-Detail Relationship

The parent record owns the child records in a master-detail relationship. When a parent record is deleted, all of its child records are also deleted (cascading deletion). The master-detail relationship provides data consistency and enforces referential integrity.

3. Roll-up Summary Fields

Lookup Relationship

Roll-up summary fields are not supported by lookup relationships. Roll-up summary fields allow you to aggregate values from child records and display them on the parent record.

Master-Detail Relationship

Roll-up summary fields are supported by a master-detail relationship. On the master record, you can define roll-up summary fields to calculate values such as sums, counts, maximums, and minimums from related child records.

4. Sharing and Security

Lookup Relationship

Lookup relationships do not automatically inherit the parent record’s sharing and security settings. Access to the parent record does not allow access to the child records that are related to it.

Master-Detail Relationship

The parent record’s sharing and security settings are passed down to master-detail relationships. Access to the master record immediately allows access to the detailed records that are associated with it. No sharing setting is available for child records.

5. Field Dependency

Lookup Relationship

Based on the presence of a value in the lookup field, we can declare a required or read-only field on the child object.

Master-Detail Relationship

Fields on the child object are automatically required and read only when a master-detail relationship is established.

Summary for Lookup vs Master-Detail

In summary, lookup relationships offer greater flexibility and allow for loose coupling of objects, but master-detail relationships offer greater data integrity, cascade deletion, and roll-up summary field capabilities. The decision between the two is determined by the specific business requirements and the nature of the objects’ relationship.

References

Types of Relationships in Salesforce

Object Relationships Overview

Related Posts

Steps for Successful Salesforce data migration

What is Data Skew?

Optimize Apex Code by Metadata Caching

Optimizing Salesforce Apex Code

Optimizing Loop in Apex Code

Optimize Code by Disabling Debug Mode

You may also like

Leave a Comment

Top 10 Salesforce Service Cloud Features Top 10 Best Practices for Lightning Flow Facts and Statistics for Salesforce’s Size and Market Share Top 5 Contract Management Salesforce Apps Top 10 Enterprise Integration Use Cases