Relationships in Salesforce

Types of Relationships in Salesforce - All You Need to Know

What is a Relationship?

Connecting different objects with each other (to connect their records, afterwards), to replicate a real-life scenario/business process is called a relationship in Salesforce.

Example - We will connect record number 1 of the “Bank Customer” table to record number 22 of the “Home Loan” table which has home loan details of that same customer.

What are the Types of Relationships in Salesforce?

Lookup Relationship

  • This relationship is used to connect objects in a simple way.
  • It works on standard objects as well as custom objects.
  • This relationship helps clients with basic things.
  • It helps to loosely connect 2 objects.
  • The only issue in the lookup relationship is that the records are not going to be strongly connected with each other, which means we can skip the selection of parent records while creating child records.

dont miss out iconDon't forget to check out: Top 5 Ways a Salesforce CRM Can Help in Building Relationship with Clients

Master-detail Relationship

  • This relationship is used when we need to connect 2 objects together in a strong bonding mode.
  • Dependency here is in such a way that the primary record controls secondary records.
  • When we delete the primary record, the secondary record gets automatically deleted. This property is called “Cascading Delete”.
  • In Master-detail relationships we have a roll-up summary feature that helps to get a summary of child records.
  • In this relationship, if we want to change the primary record, then we can take advantage of the Re-parenting feature.

Many to Many Relationship

  • A junction object is a custom object with two master-detail relationships where this junction object is on the detail side. Using this custom junction object, we can form a “many-to-many relationship between two objects.
  • The object for which the first master-detail relationship is created from the junction object is called a primary master.
  • The object for which the second master-detail relationship is created from the junction object is called a secondary master.

Hierarchical Relationship

  • This relationship is related to only “user” objects.
  • By using this relationship type, we can show the hierarchy of the organization.

Self Relationship

  • When we connect a record of object A to another record of the same object, but the object is not “user” then the relationship is called self-relationship.

dont miss out iconCheck out another amazing blog by Romil here: Get Started with Salesforce Apex Test Class | The Developer Guide

Lookup vs Master-Detail Relationship

  • Lookup relationships have loose bonding whereas master-detail relationships have strong bonding.
  • Connection is optional in Lookup relationships whereas mandatory in master-detail relationships.
  • There is no impact of primary record deletion on child record in lookup relationship whereas impact happens of primary record deletion, where child record will be automatically deleted.
  • The owner field is present on the child record in the lookup relationship whereas it is not present in the master-detail relationship.
  • We can create 40 Lookup relationship fields on one object whereas, in the case of a master-detail relationship, we can create only 2.
  • There is a special type of field that works only with master-detail relationships. It works on parent objects. This field is called a roll-up summary, it helps to show a summary of child records on the parent record.

Responses

Popular Salesforce Blogs