Salesforce Lookup vs Master-Detail Relationship

Following on from an earlier blog on Understanding Salesforce Object Relationships, this blog looks at how to choose the right relationship data type.

 

The factors that will usually help me decide when to use lookup or master-detail are:

 

Questions Master-detail
Lookup
Do the data objects of the business model have a loose binding? No Yes
Is the related object field not required? No Yes
Do I need to worry about the visibility of the records? Yes No
When the master record is deleted, does the detail related record have  to be deleted? Yes No
Will there be any calculations needed for the related list? Yes No

 

For detailed information on master-detail and lookup, check out:
https://www.salesforce.com/us/developer/docs/api/Content/relationships_among_objects.htm

 

The questions are not just restricted to the above. As you design the data model, there are more questions that you can factor in making a better decision. Let’s take a look at some scenarios and study on how the choice is made.

 

Scenario #1:

A School can only have one Hall. A Hall must be associated with a School.

 

Implementation:
The scenario above indicates that the Hall belongs to just one specific School. A rational  conclusion from there is the Hall must co-exist with the School.
Looking from the perspective of the guideline, one obvious question will help determine the choice is: Will there be a Hall when the School record is deleted? No is the answer. The question prompts us to use the Master-detail relationship in addition to the following reasons:

  • School and Hall have a tight binding. When the School is deleted, the Hall record should be deleted along with the master record.
  • When creating a Hall record, it needs to be associated with a School. Hence, the School field is a required field while creating a Hall record.

 

 

Scenario #2:

One School can have many Teachers. The Teachers can only work full time in one School.

 

Implementation:
This requirement is not as direct as scenario #1, however, the guideline questions are still applicable:

  • From the given requirement – The Teachers can only work full time in one School:

    • Even though the Teacher can only be tied to a School, however, if a School is shut down, the Teacher can always be associated to a different School. This indicates that the School and Teacher do not have a tight binding and removing the School does not result in the deletion of the Teacher.
  • In addition:
    • There is no visibility restriction that need to be applied to the records

 

From the above considerations, we will choose for the Teacher record to lookup to the School field.

Get in touch today to see how WDCi can help your business.