Junction Object in Salesforce

0
833
THE JUNCTION OBJECT IN SALESFORCE

The Problem Statement

Let’s start with an example, You have a requirement where one parent object can be related to multiple child records and one child record can be associated with multiple parent records.

Now, Here if you try to clone the Child/Parent Object and associate it with other Parent/Child Record. It would be challenging to manage the data and there would be duplicate records in Salesforce.

Solution: Junction Object

To Solve the above problem, Salesforce has introduced Junction Object which is a Custom Object with Master-Detail Relationship.

Let’s talk about a scenario, You have Programs(Code) & Bug ( Error ) in your Salesforce Org. In this scenario, one Program can be associated with multiple errors and vice versa.

Create Junction Object

As per the above scenario, We have 2 objects ( Program, Bug ) and We need the third object (Junction Object) which will have 2 parents Program & Bug.

Create the below Objects in your Salesforce Org

  1. Program
  2. Bug
  3. Program Bug
Program Object in Salesforce
Program Object in Salesforce
Bug Object in Salesforce
Bug Object in Salesforce
Program Bug Object
Program Bug Object

As we discussed that a Junction Object is a custom object with 2 Master-Detail Relationships. Let’s Create 2 master detail fields on Program Bug Object. 

  1. Master-Detail with Program
  2. Master-Detail with Bug
Junction Object in Salesforce
Junction Object in Salesforce
Junction Object in Salesforce
Junction Object in Salesforce

Primary Relationship in Junction Object

As the junction object is the child object with the Master-Detail object so a question comes into mind which Master Object will give its security settings to Junction Object?

The answer is Primary Relationship. The primary relationship is the relationship that was created first.

If you do not know which relationship was created first, you can use Workbench to find it.

  1. Log in to Workbench
  2. Select info tab
  3. Select Standard & Custom Object
  4. Select Junction object from the dropdown
  5. expand Fields and expand your relationship fields
  6. Check relationship order field
  7. Lowest relationship order is the primary relationship
Primary Relationship field in Salesforce
Primary Relationship field in Salesforce

Standard Junction object

One of the favorite interview questions is what is the standard junction object in salesforce.

Here is the list of some standard junction object

  1. OpportunityLineItem
  2. PriceBookEntry
  3. AccountContactRelation
  4. OpportunityContactRole

Reports on Many-to-Many Relationships

The following standard report types are provided by salesforce to report on junction object

  1. Primary master with junction object and secondary master.
  2. Secondary master with junction object and primary master.

Resource

LEAVE A REPLY

Please enter your comment!
Please enter your name here