Salesforce Junction Object
Before Moving on to understand the Salesforce Junction Object, let us first understand the types of relationships offered by Salesforce.
Relationship Types in Salesforce
Relationships in terms of Salesforce mean how the Objects are connected. Relationships in Salesforce are used to build a connection between the Objects. The Salesforce platform offers the following types of relationships: –
1. Master-Detail Relationship
Master detail Relationship in salesforce is a parent-child relationship in which the master objects control certain behavior of the detail object. Master detail relationship is tightly Coupled. For Example, One Object is considered as the Master and the other as the Detail. If you delete the record of the Master Object, the information of the Detail Object will get deleted automatically.
2. Look-Up Relationship
A lookup relationship essentially links two objects together so that you can “look up” one object from the related items on another object. The Objects in a Look-Up Relationship are connected loosely. It means that if you delete the record of an Object, it will not impact the linked Object.
Lookup relationships can be one-to-one or one-to-many.
3.Many-to-Many-Relationship
A many-to-many relationship allows each record of one object to be linked to multiple records from another object and vice versa. Records of a particular object can connect with various records of different objects and vice versa.
4. Self Relationship
A Self-Relationship in Salesforce is a lookup relationship to the same object. It means an Object is creating a relationship with itself.
5. External Relationship
External Lookup Relationships are used when you want to connect a child object to a parent External Object. The Child object can either be a standard, Custom or an External object. This field is used to connect the external Object with another external object.
What is Junction Object:
A junction object is a custom object. you can create Many-to-Many relationships by establishing two Master-Detail relationships or look up relationship on the same object. The object on which these two Master-Detail relationships are created is known as the Junction Object.
How to Create Junction Object in Salesforce:
Junction objects generally start off from a creation of new custom object (Account Contact Relationship). After defining a new custom object, the user proceeds to define a master-detail relationship between the objects (Account and Contact) he wishes to link together.
Now For example we will create a junction Object as Account Contact Relationship.
Follow these steps to create a new custom object:
1. Navigate to Setup.
2. Click on Object manager, then click on ‘Create’ select on ‘Custom Object’ as ‘Account Contact Relationship’
3. The Custom Object Wizard will then appear. This wizard walks users through the custom object creation process. A user needs to add the fields needed in the custom object he’s creating. Follow along the wizard’s steps to complete these fields.
4. Save everything. A new custom object is now up. This object will serve as the junction object later.
Define the Relationship:
Now in above section we created junction object (Account Contact Relationship), now we can start defining two master-detail relationships to link objects together (Account and Contact).
Start by defining the primary relationship first.
1. Open the custom junction object (Account Contact Relationship).
2. Click on the Fields & Relationships and Then New field.
3. Select Master-Detail Relationship under the field type.
4. Choose one object (Account) that will link to the junction object. Click on that object. Now, this first linked object holds the primary relationship distinction.
5. Define the Sharing Setting options. This feature determines user access to the master records. Changes and sharing of master records will affect the corresponding associated records as well.
6. Fill all the details as per requirement and save it.
7. Now, we need created the second master-detail relationship. This becomes the secondary relationship. Open the junction object and follow the same steps as above. The user needs to select the other master object that needs to link to the junction object.
Best practices for the creation of Junction Object in Salesforce
• The first master-detail created on the junction object is known as the primary master
• The second master-detail created on the junction object is known as the secondary master.
• Whosoever is the owner of the primary master will be the owner of corresponding child records.
• If we delete any one of the masters records the corresponding child records will get deleted too.
Points to remember while creating a Junction Object in Salesforce
• You need to customize an object so that it can be used as the junction object. Steps in customizing an object for this purpose differ from edition to edition.
• You need to first check if the objects to be related already exist.
• Check the page layouts of master objects for the lists.
• The objective for this is to maximize the effectiveness of the relationships.
• The ability to create many-to-many relationships is available only in the following editions: Salesforce Classic, Salesforce Lightning Experience, Group, Contact Manager, Enterprise, Professional, Developed, Unlimited, Performance, and the Database.com.
2 thoughts on “What is junction object and how to create it?”