Salesforce Object Relationships
Relationships are used to link objects together.
There are several types of relationships in Salesforce:
Relationships in Salesforce
Relationships in Salesforce are essential for linking objects together and structuring your data effectively. Here’s an overview of the different types of relationships available:
Lookup Relationship:
- Description: This is a loose relationship where a record in one object is linked to a record in another object. If the parent record is deleted, the related child record’s lookup field is cleared, but the child record itself is not deleted.
- Use Case: Suitable for situations where the relationship between records is not critical, and the child record should remain even if the parent record is removed.
Master-Detail Relationship (MDR):
- Description: This is a tightly coupled relationship where the parent record (Master) controls certain aspects of the child record (Detail), including visibility, ownership, and deletion. If a Master record is deleted, all related Detail records are also deleted.
- Use Case: Ideal for situations where the child record’s lifecycle is dependent on the parent record, and you want the child record to inherit the parent’s ownership and sharing settings.
Many-to-Many Relationship (Junction Object):
- Description: Achieved through a custom object called a junction object, which has two Master-Detail relationships linking to two different objects. This allows records of one object to relate to multiple records of another object and vice versa.
- Use Case: Useful when each record of one object needs to be related to multiple records of another object and vice versa. For example, a “Course Enrollment” object relating “Students” and “Courses”.
Self-Relationship:
- Description: A lookup relationship where a record references another record of the same object type. This is often used to model hierarchical relationships within a single object.
- Use Case: Effective for scenarios where records need to refer to other records of the same type, such as a “Contact” referencing another “Contact” to indicate a manager-subordinate relationship.
External Lookup Relationship:
- Description: Links a child standard, custom, or external object to a parent external object using the standard External ID field on the parent external object. When creating this relationship, the External ID values in the parent object are matched against the values in the child’s external lookup field.
- Use Case: Useful when integrating with external systems and needing to relate Salesforce data to records in those external systems.
Indirect Lookup Relationship:
- Description: Connects a child’s external object to a parent standard or custom object by matching fields between the parent and child objects. This is used to associate external records with Salesforce records without requiring a direct lookup.
- Use Case: Suitable for scenarios where external records need to be linked to Salesforce records based on a matching key field.
Hierarchical Relationship:
- Description: A specialized lookup relationship available only for the User object, used to model hierarchical relationships within the User object, such as reporting structures where one user can have a manager or supervisor.
- Use Case: Ideal for modeling organizational hierarchies or reporting lines within a Salesforce org.