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 to use Lookup and Master-Detail Relationship. Let us see the differences between Lookup and Master-Detail Relationship (Lookup vs Master-Detail) using the parameters below

  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

LookupMaster Detail
It is optional, and the parent record is not required to create a child record.It is a required field, and a parent is needed to create a child record
It is loosely coupledIt is strongly typed.
A rollup summary can not be createdA rollup summary can be created on the parent record.
The lookup field is not required on the page layoutThe master detail field is required on the page layout.
The parent record does not control the record ownership of the child recordThe parent controls the record ownership of the child’s record.
We can create 40 lookup fields by default, with a hard limit of 50.We can create 2 master-detail fields. Mostly, we have seen this in a junction object.
It does not cascade delete. Parent record deletion does not delete the child records.It cascades deletes. Parent record deletion also deletes associated child records.

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

Related Posts

You may also like

Leave a Comment

Top 10 Flow Enhancement in Spring’25 Release 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