In Salesforce, a relationship is a two-way link between two objects. We can use relationships to bind items together, as well as to build connections and display data about connected objects.
Different types of relationships in Salesforce: -
1. Lookup Relationships
2. Master-Detail Relationship
3. Many-to-Many Relationships
4. Self-Relationship
But Basically, We Are Used Two Relationship In Salesforce That Is: -
1. Lookup Relationships
2. Master-Detail Relationship
Lookup Relationships:
Both objects are weakly connected in this case, which implies that if one is destroyed, the other will not be deleted.
The behavior of the Look-Up relationship:
- When a parent's record is removed, the child's record remains.
- In a lookup relationship, we can't build a roll-up summary field.
- In look-up relationships, parent and kid records have their own sharing and security settings.
- The Look-Up relationship field is not required by default, but we can make it so in lightning by checking a box.
- A total of 40 look-ups are allowed per object
Some important points to remember:
When a child record is deleted and then restored from the recycle bin, the master-detail relationship is lost at the time of deletion and is not restored once the child/detail is restored.
We can convert a master-detail to a look-up if the lookup field in all records has a value, and we can convert a look-up to a master detail if there is no roll-up summary field available.
How to create Lookup Relationships in Salesforce
- 1. From Setup, go to Object Manager | Favorite.
- 2. Select Fields & Relationships from the sidebar.
- 3. Click New.
- 4. Choose Lookup Relationship and click Next.
- 5. For Related To, choose Contact. ...
- 6. Click Next.
- 7. For Field Name, enter Contact, then click Next.
- 8. Click Next, Next, and Save.
Master-Detail Relationship
In this type of relationship, one object acts as a master and the other acts as a detail object. In other words, this relationship is similar to that of a parent and a child. When we want two objects to be strongly tied or dependent on each other, we utilize this form of relationship.
The behavior of Master-Detail relationship:
- When a master record is erased, the child/detail record it refers to is also deleted.
- Both items in a master-detail connection are firmly related to each other.
- The detail records' sharing and security settings are inherited from their master settings.
- This relationship can be defined between custom items and between standard and custom objects. When constructing relationships between standard and custom items, keep in mind that the standard object must be on the master side.
- In master-detail relationships, roll-up summary fields can be used to derive values from child records using aggregation functions like Count, Sum, Min, and Max.
- On the page layout of the detail record, the master-detail field is necessary.
- Per object, we can only build a maximum of two master-detail relationships. Both items are firmly related to each other in a master-detail connection.
How to create Master-Detail relationship in Salesforce
- 1. Click Fields & Relationships on the custom object's Object Manager page.
- 2. Click New.
- 3. Select Master-Detail Relationship and click Next.
- 4. For Related To, choose Property.
- 5. Click Next.
- 6. Enter Property as the Field Name and then click Next.
- 7. Click Next, Next, and Save.
Reference: https://medium.com/@snehadaf02?p=9f7dab7b2cdf