Table of Contents
As we already know, Salesforce Objects are analogous to spreadsheet tables. And if you’ve dabbled in databases, you would know that you could relate one table to another using a foreign key. So, shouldn’t we be able to do the same with Salesforce Objects?
Salesforce offers platform functionalities that enable us to create relationships between Objects.
What are Object Relationships in Salesforce?
Object Relationships is a special field type in Salesforce that facilitates a two-way association between two objects in Salesforce. Object Relationships enable us to link one object to another.
Let’s take the example of Account and Contact Objects. When you look up an Account Record on the platform, you can find Contacts related to the Account under the Related tab. This is an example of a standard relationship in Salesforce.
Now that we’ve acquired the fundamental concept of Object Relationships let’s look at the type of Object Relationships in Salesforce.
Types of Object Relationships
Let’s look at the two main types of object relationships in Salesforce.
As the name suggests, a Lookup Relationship enables us to “look up” one object from the related items on another object. Even though the two objects are linked, security changes and deletion on one have no effect on the other, making it a loosely coupled relationship. The Accounts and Contact relationship has given above is an example of a Lookup Relationship.
The Master-Detail relationship is analogous to a parent-child relationship. Changes on the Master Object reflect on the Detail Object, making it a strongly coupled relationship.
For example, let’s say you have an object Chain that holds information on your business’s various chains. Let’s say you have an Employee object to keep track of employees working in the various Chains. If a certain Chain shuts down, it would be convenient if related objects such as Employees are automatically deleted with it.
The Solution: Creating a Master-Detail Relationship with the Chain Object as the Master and Employee Object as the Detail would be ideal for this situation.
How to differentiate between lookup and master-detail relationships
Let’s look at some of the core concepts that can help us differentiate between Lookup and Master-Detail Relationships.
Steps to Create a Custom Object
Let’s create a custom object called Favourite to enable potential customers( i.e., Contact Objects) to favorite the properties they like. We’ll be using the DreamHouse App for convenience.
1. Click on the gear icon ( ) on the top-right corner of your org and select Setup.
2. Click on the Object Manager tab.
3. Click on the Create drop-down menu on the top-right corner of the page and select Custom Object.
4. On the New Custom Object page. Fill in the following :
Plural Label: Favourites
5. After saving this custom object, check the box for Launch New Custom Tab Wizard. Leave the rest of the values as it is and click Save.
6. Once directed to the New Custom Object Tab page, click on Tab Style Field and choose a style of your liking.
7. Click Next, Next, and Save!
Steps to Create a Lookup Relationship
We’ll create a Lookup Relationship field on the Favourite Object, enabling us to link Contacts with the Properties they have on their Favourites List.
1. From the Object Manager page of the Favourite Object, select Fields & Relationships from the sidebar.
2. Click New on the top-right corner.
3. In the New Custom Field Page, Select Lookup Relationship as Field Type.
4. Click Next.
5. Choose Contact for Related To.
6. Click Next.
7. For Field Name, select Contact, then click Next.
8. Click Next, Next, and Save.
Steps to Create a Master-Detail Relationship
Let’s create a Master-Detail Relationship with Property as the Master Object and Favourites as the Detail Object. This is done so that if a Property Object is deleted, all associated Favourite Objects are deleted along with it. ( The process of creating this relationship should be quite easy, considering the steps are similar to that of a look-up relationship creation).
- From the Object Manager page of the Favourite Object, select Fields & Relationships from the sidebar.
- Click New on the top-right corner.
- In the New Custom Field Page, Select Master-Detail Relationship as Field Type.
- Click Next.
- Choose Property for Related To.
- Click Next.
- For Field Name, select Property, then click Next.
- Click Next, Next, and Save.
NOTE: When you create an Object Relationship, ensure that the relationship field is created on the detail object.
Steps to Add and View A Favourite Property
Now that we’ve created a Favourite Object and its associated Object Relationships. Let’s take a look at how to add and view a Favourite Object.
1. Click on the App Launcher and select Sales.
2. Click Property from the Navigation Bar. (If you don’t find it, it should be under More)
3. Click on any property of your choice.
4. Under the Related tab, you’ll find Favourites.
5. To Add a new Favourite, Click New.
6. Enter a Favourite Name. Choose a Contact(optional).
7. Click Save!
That was it!
What’s the point of all this? If you have this question running through your mind. Do the following experiment to understand the concept more: Delete any one object relationship from the Favourite Object and notice the changes in your org. Now try the same with the other. Now, go experiment. As they say, practice makes perfect!