Salesforce Junction Objects
A common use case you will encounter on your journey through Salesforce configuration is the need to have many-to-many object relationships. If this terminology is unfamiliar to you, never fear! In this article I will be running you through a comprehensive guide to object relationships, and how you can maximise functionality while minimising configuration time.
What Are Object Relationships?
Object relationships in Salesforce can be roughly equated to a relational database, with a lookup field acting as a primary key between the tables. This is apparent when you export values from a lookup field and are given a Salesforce ID value, as that is how the tables have been related.
In Salesforce there are two main kinds of lookups, which relate to the type of lookup we are performing.
- Lookup Field
- This relates a source record to a single target record. This type of lookup can be one-to-one or one-to-many
- In this case, a related list would be added to target as you could ostensibly relate other source records to that same target
- You can have multiple lookup fields on a single record, but not to the same object
- This relates a source record to many target records. The is a strict one-to-many relationship, where every target (or child in this case) must have a source record.
The case that we are missing, as you might already be able to tell, is a many-to-many relationship between two objects.
Let’s take this use case for example. I have a number of properties that are for sale, and a number of contacts bidding on the properties. For every bid placed I need to relate the property to the bidder on a dynamic basis without having to put in static lookups for each of those objects on either.
The solution to this is to create a junction object, which is essentially a custom object to link these two objects together. This will allow us to create as many “Bid” records as we want, potentially related to the same contact and property, without having to change anything on either of those objects.
Functionally, this couldn’t be any easier to set up! All you need to do is go to your “Object Manager” and create a new custom object, in our case, named “Bid”.
Once that is created, go to “Fields & Relationships” and add two lookup fields. In our case these are lookup fields to the custom object “Property” and the standard object “Contact”.
Once those are created, you can start creating “Bid” records, and voila! we have our junction object.
If you are ever struggling with the concept just think of a junction object as an Opportunity Product, it links together the Opportunity and the Product data without requiring changes to either of those records.
Try it yourself and comment if you have any questions.
We hope you enjoyed this article and found the information to be beneficial. If you would like to read more of our articles, then please click here.
Leave a Reply