July 8, 2017

Salesforce Object Relationships: Master Detail


You can think of Salesforce as a large database. You can think of Salesforce objects as spreadsheets within that database. In order to be able to relate on spreadsheet to another spreadsheet or really one object to another object, you need to build a relationship. 

Salesforce has created a formal way to establish those relationships with the following areas.

  • Master-Detail
  • Many to Many
  • Lookup
  • External Lookup
  • Indirect Lookup
  • Hierarchical

These are detailed here.


Let's take a closer look at the first one.

Master-Detail



This relationship "closely" connects the two objects that you are trying to relate. It establishes a parent - child relationship between the two. This is important because it extends the relationship to the sub-detail.  This means there are certain behaviors that you need to be aware of for this type of relationship.

In this diagram, there are two custom objects, States and Cities. If you wanted to closely relate each City to the state that it was included in, you could build a Master (States) - Detail (Cities) relationship between the two objects.



Deleting Behavior
Deleting a detail record moves it to the Recycle Bin but leaves master record intact.
Deleting Master also deletes the child.
Undeleting restores the master and the child. (and sub-child)
Deleting a detail (child) then deleting master you cannot undelete, because the relationship is gone.  

In our example, if you deleted West Virginia, then all of the cities associated with West Virginia record would be deleted.

Reparenting
By default, records can't be reparented.
Admins can allow it when defining the relationship.

This would be if you would want all the cities that were associated with West Virginia, to be re-associated with Ohio. Doesn't make a lot of sense here, but in some cases it might. 

Owner
The detail record is automatically set to the parent owner and it not available on the detail record.
The detail can't have sharing rules, manual sharing, or queues because this requires an owner field.

Every City associated to West Virginia in our example would have the same record Owner as the Owner of the West Virginia record. This means if I share West Virginia, I share all the cities.  

Security
Detail records inherent the Master security settings.

If you have access to West Virginia, you have access to the City records.

Page Layouts
The field linking the objects is required on the detail record.

On the Cities object page layout, you might have the field that allows you to associate the parent. In this case, it associates to States.

Standard Objects
Standard objects can be a master.


Number of Records Related

Less then 10,000 child records is best practice


Number of Relationships on Custom Object

Each custom object can have up to two master-detail relationships and up to 25 total relationships

The Related To entry can’t be changed after you save the relationship.


There are some additional benefits of using the Master-Detail relationship within Salesforce, including Roll-up Summaries that allows summaries of the detail records to be displayed on the Master record.  This would allow you to see how many cities that there are associated to West Virginia (3 in our diagram). 

If you are new to Salesforce, you will be using the Master-Detail relationship a lot and it is good to really spend time understanding these behaviors.




  

No comments:

Post a Comment