DEV Community

Cover image for Relationships in Salesforce

Relationships in Salesforce

Sushrut Mishra
Software Engineer || Salesforce || Content Writer
・2 min read

We have already talked about Objects (Standard & Custom both). I stated that a Salesforce Org can have multiple objects and in many cases, objects need to be connected with each other.
This connection that we are talking about is called Relationship of Objects.

What is Object Relationship?

A two-way linking of objects in Salesforce is called an object relationship. An object relationship is salesforce can be created by creating a custom field.
Say, for example, you have created a relationship between Account and Contact objects. Now when you access the child object, you can also view and access the shared details of parent object.
Normally, in Contact Object, you can see a field named Account Id. This represents relationship between the Contact records and associated Account records.

Types of relationships -

The most commonly talked about relationship types in Salesforce are -

  1. Lookup relationship
  2. Master-Detail relationship
  3. Hierarchical relationship The two most important and talked about are -

Lookup Relationship

In this relationship, both the related objects are loosely coupled, i.e. the deletion operation on one object will not affect another object. If one gets deleted, other will remain as it is, doesn't matter if the deleted object is Parent or Child.

To create a lookup relationship, create a new custom field and select Look Up from the option -

new field


  • Can't create a Roll-Up summary in Look-Up relationship.
  • The look-up field is not mandatory by default. However, you can make it mandatory.
  • The maximum number of look-up fields are 40 per object.

Master-Detail Relationship

In this relationship, one object is a Master and the other is detail or child. Unlike Look-up relation, the objects here are tightly coupled.
We can use this relationship when we need two objects to be closely dependent.

To create a Master-Detail relationship, open the object where you want to create and click on 'New' in fields tab.

Now select Master-Detail option from the menu -
(Below Look-up Option)
MD relation

  • When you delete the master records in Master-detail relation, the child records get deleted too.
  • Master-detail fields are Mandatory by default.
  • When creating this relationship between Custom and Standard objects, remember that Standard objects are always on the master side.
  • A maximum of 2 MD relationships can be created per object.

  • The Master Detail relationship allows you to have Roll-up fields too. However, the roll up field can only be created on master side.
    roll up

Learn more about Salesforce relationships here -
Salesforce Relationships

Discussion (0)