Tag: master-detail relationship

Salesforce Relationships Overview

Salesforce Relationships Overview

Salesforce Relationships allows user to build some powerful and useful queries to fetch data. In Force.com data can be abstracted by creating simply relationships between objects. Relationships allows user to build some powerful and useful queries to fetch data. A relationship field in salesforce.com stores the parent record ID in a pre-defined relationship. Salesforce Relationships are of three types, they are lookup relationship, master-detail relationship and many to many relationship. For each relationship user can specify up to 5 levels in a query.

Salesforce Relationships – Types.

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

Lookup Relationship in Salesforce.

Lookup relationship creates a simple (foreign key) relationship that links one object to another object. These can be used to create one-to-one and one-to-many relationships. When displaying records in the salesforce.com UI, the platform generates a link to the related record allowing you to navigate from record to related record.

Master-Detail Relationship in Salesforce.

A master-detail relationship can be created between “parent object” and a “child object“. The two object will be the parent, or “master” object and its child, or “detail” object. Parent Object will also called as Master Object and Child Object will be called as Detail Object.

  • Detail objects cannot created without a master object once created, Master-Detail Relationship cannot be change
  •  Detail objects inherit the security from the master object and deletes cascade from the master to the detail objects.

Many-to-Many Relationship in Salesforce.

Many-to-Many Relationship in Salesforce can be created using a Junction object. Here a junction object is used to create Many-to-Many Relationships.

What is Junction Object?

In this case salesforce.com uses an intermediate object, which they refer to as a junction object. To implement a junction object, simply create a custom object and add two master-detail relationship. An issue with junction objects involves usability. When you add the junction object as a related list on a page layout, the user may have to make an extra series of clicks to create new records or navigate back to the original record. This can be somewhat confusing from a UI perspective.”

How to create Master-Detail relationship in Salesforce

How to create Master-Detail relationship in Salesforce : In this training tutorial we are going to create and gain some knowledge on how to create a Master-detail relationship in salesforce between objects. In our previous training tutorial we learned about different types Relationships in Salesforce and their characteristics.

Relationship is the way in which two or more people or things connected with each other. Here Master Object is also called “Parent Object” and Detail Object also called “Child Object“.

Characteristics of Master-Detail Relationship

  • Child record must have a  associated parent.
  • Cascade record-level security.
  • Cascade record deletion.
  • Roll-up Summary fields can be established.
  • Standard objects can not be a detail object.
  • Standard Objects can be a Master object
  • Maximum 2 Master-Detail Relationships can be created to a Object.
  • Records can be re parented.

Now we are going to create Master-Detail Relationship between Custom College Object, Student Object, Course Object and Employ Objects. In this example we are taking Custom College Object as Master or Parent object. And Student Object, Course Object and Employ Objects will be child Objects or Detail objects for Custom College Object(Parent or Master object).

  How to create Master-Detail relationship in salesforce.

In the first go to detailed view of Custom student Object.Then go to custom fields and Relationships section.

Detailed view of Object => Custom fields and Relationships => New => Select Master-Detail Relationship

How to create Master-Detail relationship in Salesforce

Now select New. Now we are taken to new window to selected Related to Object(Master Object). In the Picklist select custom College object.

How to create Master-Detail relationship in Salesforce

Now Select Next Button again we are taken next step where we are required to give Field Label, Field Name, select sharing setting and Allow child records to be re parented.

How to create Master-Detail relationship in Salesforce

Select Next and in next step make the field-level security for reference field. and select next.

How to create Master-Detail relationship in Salesforce

How to create Master-Detail relationship in Salesforce

In the next Step Save it.

How to create Master-Detail relationship in Salesforce

Go to Student Object in detail view which we observe Master-Detail Relationship is created between College and Student Object. Like wise create Master-Detail relationship between College-Course, College-Employ Objects. Make College object as Master Object.

Now go to  College Tab to create new record in College object.

How to create Master-Detail relationship in Salesforce

Enter College name and Save it.

How to create Master-Detail relationship in Salesforce

Now got to detail view of the record and we observe Student object, Dept Object and Course Objects as Child Objects for College Object(Master or Parent Object).

How to create Master-Detail relationship in Salesforce

Note : For an Object with a Master-Detail Relationship field the standard field called Owner Field can not be available. The Owner of the Master record becomes the owner of the child record.