In this video, I will be explaining how the junction object works in Salesforce.
A junction object in Salesforce establishes a many-to-many relationship between objects. The junction object acts as a middleman between the preceding objects whether the 2 objects are custom or standard. What is necessary is to have the master-detail relationship established with the junction object—one with each of the objects.
The purpose of this is to offer flexibility when relating records from multiple parent records to multiple child records.
An example already made in salesforce is the opportunity-product object (which is a junction object) This is in between the opportunity and product object in salesforce. Because many opportunities can have many products or many products can be associated with many opportunities.
The advantages of a junction object:
Better reporting on related records.
Workaround complex scenarios and scalability to have data organized in the appropriate manner.
Better data management.
Let's go through the example together.
We will use 3 objects:
Your team works in real estate owning multiple properties from apartments to triplexes. Your business rents out one of the owned real estate.
Properties: This object will store information about your rental properties, including address, unit number, square footage, and property type (apartment, single-family home, etc.).
Maintenance Requests: This object serves as the central hub for capturing and managing tenant requests. It can include fields like:
Description of the issue
Priority level (urgent, moderate, low)
Attachments (to document the issue)
Service date/time
Tenant (Using Contacts Object): Links the request to the specific tenant who submitted it.
The junction object will be maintenance requests. There could be many properties with many tenants. Properties can have many tenants and many tenants can live in one of those properties.
The Relationship Breakdown
Properties and Maintenance Requests: A single property can have multiple maintenance requests. This is a one-to-many relationship. For example, a single apartment building (Property) might have multiple maintenance requests (Plumbing, Electrical, etc.).
Tenants and Maintenance Requests: A single tenant can submit multiple maintenance requests. This is also a one-to-many relationship. For example, a single tenant might report multiple issues within their apartment.
Tenants and Properties: A tenant can occupy one or more properties (e.g., a family renting multiple units in the same building). This is a many-to-many relationship, as a tenant can be associated with multiple properties and a property can have multiple tenants. This is often handled in Salesforce by using a junction object, but in this simplified example, we used the Tenant object directly to link to the Properties object.
Once the objects are available in your Salesforce instance.
From object manager
Select junction object (in this example it is the Maintenance requests object)
Click on field and relationships
click new
select Master-detail relationship
select the object you want to relate it to
Add the field name of your choice or it could be the default
Complete the rest of the field creation steps.
Resources:
Many-to-many relationship
https://help.salesforce.com/s/article...
Github:
https://github.com/emon654
Check out this awesome blog:
https://definingaffect.com/
**Time Stamp**
00:00 - Intro
00:53 - Example Opportunity and Product object
01:40 - Advantages
02:03 - Custom example explanation
03:55 - Sample report
04:35 - Looking at an example record
05:17 - Outro