What is Junction Object in Salesforce?
Updated · By the Clientell AI team · How we write
A junction object is a custom Salesforce object with two master-detail relationships. It links two other objects so that each record on one side can relate to many records on the other side, and the reverse. This is how Salesforce models a many-to-many relationship. Deleting a master record also deletes its related junction records.
Key facts
- What it is
- A custom object that sits between two objects in a many-to-many relationship
- How it is built
- Two master-detail relationship fields, one to each parent object (Developer Guide)
- Classic example
- Job Application between Position and Candidate
- Delete behavior
- Deleting a master record also deletes its related detail (junction) records
- Access
- A detail record's access comes from its masters, not from its own sharing (Apex Developer Guide)
- Relationship cap
- A custom object can have up to 40 custom relationships (master-detail and lookup) (Salesforce Help)
Clientell AI, the AI Salesforce admin, documents how Junction Object is used in your org in a read-only scan, and flags anything risky or unused. See org documentation
Try it in Clientell AI
“Document how Junction Object is used in my org and list anything that looks risky or unused.”
Clientell AI reads your org first. Platform deployments include rollback. How security works.
What is a junction object in Salesforce?
Salesforce has no built-in many-to-many field. A lookup or master-detail field points from one child to one parent. If one candidate can apply for many positions, and one position can have many candidates, a single field cannot hold that.
The fix is a third object in the middle. That is the junction object. Each junction record links one record from each side. Many junction records together build the many-to-many relationship. Salesforce describes this as using master-detail relationships to model many-to-many between any two objects (Developer Guide).
What does a junction object look like in practice?
Take a recruiting app with a Position object and a Candidate object. You create a custom object called Job Application. It has two master-detail fields: one to Position and one to Candidate.
Asha applies for two positions, and the Salesforce Admin position has two candidates. Three junction records capture all of that.
| Job Application record | Position (master 1) | Candidate (master 2) |
|---|---|---|
| JA-0001 | Salesforce Admin | Asha |
| JA-0002 | Salesforce Admin | Ravi |
| JA-0003 | RevOps Analyst | Asha |
How do you create a junction object?
Create both parent objects first. The first master-detail field you create is the primary relationship and the second is secondary (Trailhead). Try it in a sandbox.
- Setup > Object Manager > Create > Custom Object. Name it Job Application. Skip the tab unless users need one.
- On Job Application, go to Fields & Relationships > New > Master-Detail Relationship. Point it at Position.
- Create the second Master-Detail Relationship field. Point it at Candidate.
- Add Job Application as a related list on both the Position and Candidate page layouts.
- Optionally, add roll-up summary fields on the parents to count or total the junction records.
- Result: each Position page lists its candidates, and each Candidate page lists their positions.
How does a junction object behave?
The junction object is on the detail side of two master-detail relationships, so it follows master-detail rules.
Delete: if a master record is deleted, all its related detail records are deleted too. Deleting a Candidate deletes that candidate's Job Application records.
Owner and sharing: the Owner field is not available on a detail object, and it has no sharing object of its own. With the Controlled by Parent setting, a user can act on a junction record if they can perform the same action on all associated master records (Salesforce Help).
Roll-ups: each master can hold roll-up summary fields over its junction records. The default is 25 per object, and Support can raise it to a hard maximum of 40 (Salesforce Help). See roll-up summary fields.
Junction object vs lookup relationship
Pick the lighter option when it is enough. A lookup is loose, and a junction object is tight. Read more on master-detail relationships.
| Lookup | Junction object (two master-detail) | |
|---|---|---|
| Relationship shape | One-to-many | Many-to-many |
| Required parent | Optional | Both parents required |
| Delete a parent | Child stays (unless cascade delete is on) | Junction records are deleted |
| Roll-up summary on parent | Not available | Available |
| Sharing | Child has its own owner | Access comes from the masters |
What are common junction object mistakes?
Most problems appear at creation or at delete time. Each has a fix.
- Using lookups for both fields. Fix: use master-detail if you need cascade delete and roll-ups, or accept that records can be orphaned.
- Creating the two fields in the wrong order. Fix: the first field becomes primary, so create it for the parent that should drive layout and sharing.
- Deleting a parent without a warning to users. Fix: tell users that junction records go with it, and keep a backup first.
- Expecting an Owner field. Fix: use sharing on the masters, since the junction has no owner.
FAQ: Junction Object in Salesforce
What is a junction object in Salesforce?
A junction object is a custom object with two master-detail relationships. It connects two other objects to model a many-to-many relationship.
How many master-detail relationships does a junction object have?
Two. One points to each of the two objects it connects.
What happens when I delete a record on one side?
The related junction records are deleted too. This is standard master-detail behavior: when a master record is deleted, its detail records are deleted as well.
Who owns a junction object record?
No one directly. The Owner field is not available on the detail side of a master-detail relationship. Access follows the master records.
Why use master-detail and not lookup on a junction object?
The standard junction pattern uses two master-detail fields. That gives you cascade delete, and roll-up summary fields on both parents.
Is there a limit on relationships?
An object can have no more than 40 custom relationships, including master-detail and lookup (Salesforce Help).
Sources: Object Reference: Relationships Among Standard Objects and Fields, Trailhead: Object Relationships, Salesforce Help: Organization-Wide Sharing Defaults, Apex Developer Guide: Sharing a Record Using Apex, Salesforce Help: Custom Fields Allowed Per Object. Last reviewed .
Related Salesforce Terms
3 termsMaster-Detail Relationship
DataA Master-Detail Relationship is a tightly coupled parent-child link where the child inherits the parent's sharing and security settings, and deleting the parent cascades to delete all children.
Roll-Up Summary Field
DataA Roll-Up Summary Field aggregates values (COUNT, SUM, MIN, MAX) from child records in a master-detail relationship and displays the result on the parent record.
Custom Object
DataA Custom Object is a user-defined database table in Salesforce that stores data specific to your organization's unique business needs.
What should I read next?
More in Data
View all →Data Loader
Data Loader is a Salesforce desktop application for bulk importing, exporting, updating, deleting, and upserting large volumes of records.
Data Import Wizard
The Data Import Wizard is a browser tool in Salesforce Setup that imports up to 50,000 records from a CSV into standard and custom objects. It can insert, update or upsert, but it cannot delete or export.
Custom Object
A Custom Object is a user-defined database table in Salesforce that stores data specific to your organization's unique business needs.
Custom Field
A Custom Field is a user-defined field added to a standard or custom object in Salesforce to capture data not covered by out-of-the-box fields.
Try this on your own org
Start the 14-day free trial, no card. Clientell AI asks before it changes anything in production.
14-day free trial · No credit card required