What Is Lookup Relationship In Salesforce?
Lookup Relationship in Salesforce relates two objects together but does not affect deletion(cascade delete functionality) or security. Unlike master-detail fields, lookup fields are not automatically required, they can be made required.
When a salesforce lookup relationship is defined, records from one object(many side objects) can appear as a custom-related list on page layouts for the other object(one side object).
Types Of Lookup Relationship In Salesforce
There are derived 2 subtypes of Lookup Relationships:
1. Hierarchical Relationship
A special lookup relationship is available for only the user object. It lets users use a lookup field to associate one user with another that does not directly or indirectly refer to itself.
For example, You can create a custom hierarchical relationship field to store each user’s direct manager.
2. Self Relationship
When an object has a lookup relationship with itself, it is a self-relationship.
For example, an employee is related to another employee like a team lead reports to a manager and they both are employees.
Many-to-Many Relationship
Many-to-Many relationships can be created using master-detail or look-up relationships between any two objects. It allows each record of one object to be linked to multiple records from another object and vice versa.
To create a many-to-many relationship, simply create a custom junction object with two master-detail relationship fields, each linking to the objects needed to relate.
Junction Object
A custom object with two master-detail relationships. Using a custom junction object, you can model a “many-to-many” relationship between two objects.
Primary Relationship
It is the relation created first with any of the two master objects.
- The object with which the relationship is created first is called the primary master object.
- The detail and edit page of the junction object will use the color and any associated icon of the primary master object.
- The junction object records will inherit the value of the owner field.
- The sharing and security settings of junction objects will depend on the associated master record.
- Deleting a record of the primary object will delete the associated records of the junction object as well.
- The owner of the junction record is the owner of the primary master object record.
Secondary Relationship
The second master-detail relationship is created with another master object.
- The object with which the relationship is created later is called the secondary master object.
- This relationship does not affect the look and feel of the junction object.
- The security and sharing setting of the junction object depend on secondary relationships as well.
- Deleting a record of a secondary object also deletes the associated records of the junction object.
Note:
- Junction objects cannot be created as master objects in a master-detail relationship with another object as detail.
- In an object, we can create only 2 master-detail relationships.