Relationships in Salesforce You Should Know (2021)

Track IT Consultants
3 min readJun 30, 2021

In Salesforce, we can create two types of relationship between objects given below.

· Lookup Relationship

· Master-Detail Relationship

These are the two relationship fields available to create a relationship between objects. Creating a relationship means referring to parent records on the child object. Consider the below two data tables Department table and Employee table (Object in Salesforce).

In this example, the Department is the parent object and Employee is a child object on child object Employee we are referring the parent object data, and the field type is the relationship type.

By creating this relationship field, we establish the relationship between the objects.

If you’re familiar with the relationship concept in SQL tables, it’s the same. In SQL tables, we create the Primary key field parent object, and in the child object, we create a foreign key.

In Salesforce, each record is uniquely identified by the ‘Id’ field (Primary Key field).

This Id (Primary key) field value store in the child object record relationship field (Foreign key). But on User Interface displaying parent object Salesforce record id on child object record will create confusion to users the record Name (standard field available in all object) field value of parent object record shows on the child object relationship field.

So, in the backend, it holds Salesforce record Id.

On UI, it shows the Salesforce record Name value.

Relationship types:

· Lookup Relationship

· Master-Detail Relationship

· Many to Many Relationships

· Self-Relationship

· Hierarchy Relationship

· Lookup Relationship

Lookup relationship is also called loosely coupled relationship, lookup relationship field; by default, it’s not a mandatory field.

In a lookup relationship, child object records can exist without the parent object record.

If we delete the parent record based on the option, we can decide whether to allow deleting child record or not

Clear the value of this field.

Don’t allow the deletion of the lookup record that’s part of a lookup relationship.

If we select the first option, delete the parent record child object will not get deleted. It just nullified the relationship field value.

In the selection of the second option, we cannot delete the parent record if the record is associated with any child record.

Master-Detail Relationship:

In the lookup relationship, we cannot create Rollup-summary fields.

Master-Detail Relationship, also called tightly coupled relationships, by default M:D relationship field is a mandatory field.

In M:D relationship, child records cannot exist without a parent record.

If we delete the parent record, the child record also gets deleted.

After establishing the M-D relationship, the child object Owner field (Standard system field) will get removed.

We can create 2 M:D relationship fields in one object.

We can create a Roll-up summary field in M:D relationship.

Many to Many Relationship:

In Salesforce, we cannot create Many to Many relationships directly between the object.

To create Many to Many to the relationship, we have to use a Junction object (Custom object). In the Junction object, we have to create two M-D relationship fields to establish the Many to Many relationship fields. The junction object is used to create Many to Many relationships and this object.

Self-Relationships:

Creating a relationship with the same object is called Self-Relationship (Means Parent and child object will be the same).

We use the lookup relationship field type to create Self-Relationship.

Hierarchy Relationship:

This is a special relationship available in Salesforce. In this relationship, we can create a hierarchy relationship in the user object. We can see the standard hierarchy relationship field on the Account object too.

--

--