Skip to main content
Data

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.

Start the 14-day free trial, no card

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 recordPosition (master 1)Candidate (master 2)
JA-0001Salesforce AdminAsha
JA-0002Salesforce AdminRavi
JA-0003RevOps AnalystAsha

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.

LookupJunction object (two master-detail)
Relationship shapeOne-to-manyMany-to-many
Required parentOptionalBoth parents required
Delete a parentChild stays (unless cascade delete is on)Junction records are deleted
Roll-up summary on parentNot availableAvailable
SharingChild has its own ownerAccess 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).

Getting Started

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

SOC 2
HIPAA
ISO 27001
Salesforce Partner