What is Object Relationships in Salesforce
Object relationships are a special field type that connects two objects together.
Salesforce Object relationships is nothing but a two way association between two Objects. One Object record information is linked in another object record. In Salesforce.com, Object Relationships is created between two Object. Here the custom field of an Object record contains a link in another object record. To build many custom object in Salesforce.com, relationships plays a major role.
Let’s think about a standard object like Account. If a sales rep opens an account, they’ve probably been talking to a few people at that account’s company. They’ve probably made contacts like executives or IT managers and stored those contacts’ information in Salesforce.
It makes sense, then, that there should be a relationship between the Account object and the Contact object.
When you look at an account record in Salesforce, you can see that there’s a section for contacts on the Related tab. You can also see that there’s a button that lets you quickly add a contact to an account.
There are two main types of object relationships: lookup and master-detail.
1. Lookup Relationships
The relationship between the two objects is a lookup relationship. A lookup relationship essentially links two objects together so that you can “look up” one object from the related items on another object.
Lookup relationships can be one-to-one or one-to-many. The Account to Contact relationship is one-to-many because a single account can have many related contacts.
- Lookup relationship is a one type of relationship which form loose bond relationship between Parent object and Child object.
- In lookup Child record need not be associated to a parent.
- No Cascade record deletion happens.
- Lookup field is not required on the page layouts of the detail object.
- No Rollup summary fields can be created in Lookup relationship.
2. Master-Detail Relationships
While lookup relationships are fairly casual, master-detail relationships are a bit tighter. In this type of relationship, one object is the master and another is the detail. The master object controls certain behaviors of the detail object, like who can view the detail’s data.
The Master-detail relationships is that you can create rollup summary fields! Do take note, a single object can have a maximum of 2 master-detail relationships.
- When a record of the master object is deleted, its related detail records are also deleted.
- The Owner field on the detail object is not available and is automatically set to the owner of its associated master record. Custom objects on the detail side of a master-detail relationship cannot have sharing rules, manual sharing, or queues, as these require the Owner field.
- Master-Detail relationship is a one type of relationship which form tight bond relationship between Parent object and Child object.
- Child records should always associated to a parent they can not remain orphan.
- Cascade record deletions. When a parent object record is deleted all it’s child records get deleted automatically.
- Standard Objects cannot be a detail object(Child object). ex: Account cannot be detail object.
- The master-detail relationship fields is required on the page layouts of the detail object.
- Roll-up Summary fields can be created on Master object(Parent Object.)
- Child record inherits all security and sharing settings from it’s parent record.
Lookups vs Master-Detail Relationships
Lookup relationship | Master-detail relationship |
---|---|
Loosely coupled. | Strongly coupled. |
Roll-up summary field not available. | Roll-up summary field is available.. |
Parent record is not required when creating a child record. | Parent record is required in order to save a child record. |
Lookup fields are not required on the page layout of the detail record but if you make them a required field, it is advised! | Master-detail field is always required on the page layout of the detail record (because of the point above). |
Standard object record can be on the detail side of a custom object in a lookup relationship. | Standard object record cannot be a child. |
By default record ownership of child records is not controlled by the parent. | The parent controls the record ownership of child records. The owner field is not available on the detail record in master-detail relationship queues, sharing rules and manual sharing is not possible for detail records as it requires the owner field. |
You can have a child record without a parent. | You cannot have a child record without a parent. |
You can have a maximum of 40 lookups on an object. | You can have a maximum of two master details on an object. |
No cascade delete. | Cascade delete. |
3. External lookup relationship
We can create two special lookups on an external object apart from the standard lookup relationship. They are external lookup relationship and indirect lookup relationship.
External lookup relationship allows us to link an external object to a parent external object whose data is stored in an external data source. In other words, it allows us to link two external objects.
4. Self-relationship
Self-relationship is another example of a lookup relationship. In Salesforce, we can use lookup relationships to create self-relationship among objects; we can have a maximum of 40 self-lookups.
5. Many-to-many relationship
The many-to-many relationship in Salesforce allows us to link a child record to multiple parents.
- Many-Many Relationships between two objects can be created.
- Junction Object is used to create Many-Many Relationship.
- Junction object can also be called as Join Object.
- Junction Object links each objects in Many-Many Relationship.
We create Many-to-Many Relationship by creating two master-details relationship with a common Junction Object.
Examples and details adding soon.
Comments
Post a Comment