Junction Object

A Junction Object in Salesforce is a custom object that links two other objects to create a many-to-many relationship between them. It is not a special object type, just a regular custom object with two relationship fields, typically two master-detail relationships. Standard Salesforce examples include Opportunity Line Items and PricebookEntry.

You’ll meet this term whenever you need to connect candidates applying to multiple jobs, bugs related to multiple cases, students enrolled in multiple courses.

PRACTICAL EXAMPLE

A recruitment team needs to track candidates applying to job positions. The admin creates a custom object called “Job Application” with two master-detail fields: one linking to the Candidate object, one linking to the Job Position object. Each application record represents one candidate applying to one job.

Quick facts

  • Architectural pattern, not a field type: A “junction object” is just a regular custom object that links two others.

  • Typically two master-detail relationships: Typically, a junction object has two master-detail relationships. Deleting either parent deletes the junction record (cascade delete). The Owner field is controlled by the primary master but isn’t visible while the object remains a junction object. Access is determined by both master records. A user needs Read access to both records to view the junction record.

  • Lookups are technically valid but rare: Use lookups for cases where the junction record must survive after a parent is deleted. PricebookEntry uses this pattern with cascade delete defined at the schema level.

  • Primary vs secondary master-detail: The first master-detail field you create becomes the primary. The primary controls look and feel (color, icon), record ownership (Owner inherited from primary), and division (if your org uses divisions).
    Note: The primary master cannot be swapped without deleting the existing master-detail and recreating it, which can affect existing junction records.

  • Auto-number for Record Name: Salesforce recommends auto-number data type for the Record Name field.

  • No tab needed: Salesforce documentation states junction objects don’t require a tab. Users reach junction records through related lists on parent objects.

  • Standard Salesforce junction objects: Opportunity Line Items, PricebookEntry, Case Team Member, Account Team Member.

  • Available in: Contact Manager, Group, Professional, Enterprise, Performance, Unlimited, Developer, Database.com.

Warning icon

Note

Salesforce auto-generates two standard report types for junctions: “primary master with junction object and secondary master” and “secondary master with junction object and primary master”. The master listed first determines the scope of records in the report. To join the objects in a different order or include additional related objects, create a custom report type.

FAQ

How many junction objects can I have in Salesforce?

There is no specific limit on junction objects. The applicable limit is your edition's custom object limit (200 in Enterprise, 2000 in Unlimited and Performance)


How do I query a junction object in Salesforce?

A junction object is queried like any other custom object using SOQL. To traverse a many-to-many relationship, start from the junction and reference both masters through their relationship fields. Example: SELECT Id, Candidate__r.Name, Job_Position__r.Title FROM Job_Application__c WHERE Stage__c = 'Interview'.


Can we delete a junction object in Salesforce?

Yes. Deleting a junction object deletes the object and all junction records, removing the many-to-many relationship. To change the relationship, you may need to replace or, where supported, convert a master-detail relationship. Removing a master-detail relationship means the object no longer functions as a junction object. Deleted custom objects remain in Deleted Objects. (Setup → Object Manager → Deleted Objects) for 15 days before Salesforce permanently deletes them.