Object Relationship in Salesforce



What is a salesforce object? 

Salesforce object is a database table that stores all the information and business data. Since salesforce object is a table, its rows are referred as records and columns are referred as fields.


What are the types of objects in salesforce? 

There are 2 types of objects available in salesforce. Namely, Standard objects and custom objects.  

    1. Standard objects are the objects created by salesforce that are already present within the platform. For example, Accounts, Leads, opportunities, Cases and contacts etc. 
    2. Custom objects are objects that are created by users according to business needs. 

What is object relationship in salesforce? 

Relationship is a two-way link between 2 objects. Relationship in salesforce allows us to create a link between one object and other. Salesforce relationships are established to allow users to perform specific actions on the CRM platform. The FROM clause in a query is limited to one object. Hence, we can access two related objects by using a relationship. To establish a relationship between two objects we use the concept of primary key and foreign key. 





What are the types of relationship in salesforce? 

There are 3 types of relationship in salesforce. Namely, 

    1. Master Detail Relationship 
    2. Lookup Relationship 
    3. Many to Many Relationship


Explain Master Detail Relationship (1-n). 

In this relationship one object can be associated with multiple objects. Parent object is called as Master object and child object as Detail object. Here If the Record of the master object is deleted; Its related Record of Detail object is also deleted. 


Few important points to note,

  • Master Object Controls certain behavior of Detail Object.
  • Detail object record cannot exist without the reference to the master object record. 
  • If we restore the Master object record, then its related Detail object record is also restored automatically. 
  • Detail object inherits the sharing and security settings of Master object.
  • Master-Detail relationship field is required in detail object home page. 
  • We’ll use master detail relationship when we want detail object records to get deleted whenever Master object record gets deleted. 
  • Reparenting is not enabled by default. If the check box is checked then reparenting can be done.
  • Standard object cannot be on the detail side of relationship. 
  • Also, Standard object Lead and user cannot be on Master side of relationship.


For example, in a courier companies delivery location always has delivery schedules. If the delivery location is deleted all its schedules are also deleted. To create this type of dependencies we use Master detail relationship. 


Explain Lookup Relationship. 

This relationship involves finding value of a field based on the value in another field. This relationship links two objects but has no effect on security, Sharing settings and deletion. Meaning If the Master object gets deleted its related Detail object will not get deleted. 


For example, we have students’ final grades which needs to be related to student details. Since both objects will have Roll number field, we can use Lookup relationship to get the student details.


Points to remember,

  • Records in Detail object can exist without Master object relationship. (We can make it a requirement as not to be left blank if we want). 
  • We can use this relationship when we want to create a relationship which won't affect the Detail side of records by Master object. 
  • We can also create self- lookup relationship on the same object. 
  • Lookup relationship can be one to or one to many. 

What is hierarchal relationship? 

It is a unique lookup relationship which only user object can have. Hierarchal relationship is nothing but self-relationship on user object. This relationship is used to associate one user with another user. 


What is Many to Many Relationships? 

Many to many relationships allows each record of one object to be linked with many objects and vice versa. 

For example, in college a student can enroll to multiple hobby clubs and the hobby club can have multiple students. 


Few important points of Many to Many relationships,

  • To establish this relationship, we need to create another object to store the values. This object is called Junction object.
  • If the master's data is deleted the detail data also gets deleted. 
  • In junction object the field which is created first will become the primary master object and relationship will be called as primary relationship. 
  • Other relationship object will be called as secondary relationship object and relationship will be called as secondary relationship object.
  • Owner field will be derived from primary master object. 
  • Security and sharing settings will be derived from both. 




Comments