Creating A Many-To-Many Relationship In SalesForce

About Salesforce

 
Salesforce is a cloud-based online solution for customer relationship management (CRM). SalesForce provides all of our departments like marketing, sales, commerce, and service with a shared view of our customers with a single integrated CRM platform.
 

Relationships in Salesforce

 
A relationship is a two-way association between two objects. Create relationships to link objects with each other, so that when the users view records, they can also see related data. Avoiding data redundancy and data inconsistency, we are in need of a relationship. We can define different types of relationships like Master-Detail Relationship, Lookup relationship and Many to Many Relationship.
 

Master-Detail Relationship

 
A master-detail relationship is a parent-child relationship where the master is like a parent and detail is like a child in which the master object controls some behaviors of the detail object. Also when a Master object record is deleted then the detail object related to it also gets deleted.
 

Lookup relationship

 
Lookup Relationship is nothing but creating a relationship between two same objects. This Lookup Relationship is a self-relationship to the same object.
 

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.
 
Reading this article, you can learn how to create Many-to-Many Relationship between Student and ActivityGroup objects using StudActive (Junction Object) in SalesForce.
 
The prerequisites are for Creating a Many-to-Many Relationship in SalesForce as,
 
Register a Salesforce Free Trail account using the following link.
 
Step 1
 
Login to your Salesforce Account and click "Setup".
 
Creating the Many to Many Relationship in SalesForce
 
Step 2
 
Click the Object Manager and create the Student, ActivityGroupobject, and create the Custom Fields (Refer here)
 
Step 3
 
After creating  Student and ActivityGroupobjects,  now we can create a new object as StudActive which is a Junction Object for creating Many-to-Many Relationship between Student and ActivityGroupobject.
 
After creating Junction Object (StudActive), first, we have to create Master-Detail relationship between StudActive and Student objects.
 
Select a StudActiveobject, select the Field & Relationships in the details tab, and click "New" and select the Master-Detail Relationship and click "Next".
 
Creating the Many to Many Relationship in SalesForce
 
Select the related to object as Student and click "Next".
 
Creating the Many to Many Relationship in SalesForce
 
Enter the Field Label and Name for the lookup and click "Next".
 
Creating the Many to Many Relationship in SalesForce
 
Make visible all the field level security and click "Next".
 
Creating the Many to Many Relationship in SalesForce
 
Add the reference field to the "Page Layout".
 
Creating the Many to Many Relationship in SalesForce
 
Now, add a custom related list.
 
Creating the Many to Many Relationship in SalesForce
 
Next, we have to create Master-Detail relationship between StudActive and ActivityGroupobjects.
 
Select a StudActiveobject, select the Field & Relationships in the details tab and click New, select the Master-Detail Relationship, and click "Next".
 
Creating the Many to Many Relationship in SalesForce
 
Select the related to object as ActivityGroupand click "Next".
 
Creating the Many to Many Relationship in SalesForce
 
Enter the Field Label and Name for the lookup and click Next,
 
Creating the Many to Many Relationship in SalesForce
 
Make visible all the field level security and click Next,
 
Creating the Many to Many Relationship in SalesForce
 
Now, Master – Detail Relationship is created between StudActive with Student and ActivityGroupobjects,
 
Creating the Many to Many Relationship in SalesForce
 
Step 4
 
Now we can verify the Many to Many Relationship between Student and ActivityGroupobject with the StudActive (Junction object) through App Launcher.
 
Select the New ActivityGroup from ActivityGroupTab and enter the ActivityGroupdetails, click save.
 
Creating the Many to Many Relationship in SalesForce
 
Two more ActivityGroups were created with new ActivityGroup, and the list of added ActivityGroups are,
 
Creating the Many to Many Relationship in SalesForce
 
Already we have added the students (refer here), and the list is,
 
Creating the Many to Many Relationship in SalesForce
 
Now we can add new StudActive from StudActive tab, used in the concept of Many to Many relationship,
 
Creating the Many to Many Relationship in SalesForce
 
Enter the StudActive Name, and select the student from Student object and Select the Activity Group from ActivityGroup and click Save,
 
Creating the Many to Many Relationship in SalesForce
 
Creating the Many to Many Relationship in SalesForce
 
Three more StudActives are created and the list of added StudActives are,
 
Creating the Many to Many Relationship in SalesForce
 

Summary

 
Now, you have successfully created and tested the Many-to-Many Relationship between Student and ActivityGroup objects in a SalesForce environment.


Similar Articles