Salesforce Dictionary - Free Salesforce GlossarySalesforce Dictionary
Full Junction Object entry
How-to guide

How to build a Junction Object

A junction is just a custom object with two master-detail fields, but the order you create them and the choices you make on the first one lock in long-term behavior. Build in a sandbox, validate sharing as different user personas, and only then promote to production.

By Dipojjal Chakrabarti · Founder & Editor, Salesforce DictionaryLast updated May 16, 2026

A junction is just a custom object with two master-detail fields, but the order you create them and the choices you make on the first one lock in long-term behavior. Build in a sandbox, validate sharing as different user personas, and only then promote to production.

  1. Confirm the cardinality is genuinely many-to-many

    Sketch the relationship. If both sides really need many-to-many, a junction fits. If one side only ever has one parent at a time, a single lookup or master-detail is simpler and avoids the overhead. Confirm the cardinality with the business owner before building anything.

  2. Create the custom object with a descriptive name

    Go to Setup, Object Manager, Create, Custom Object. Name it after the relationship, not the generic concept. Use Course_Enrollment__c or Account_Project__c, not Junction1__c. Leave Allow Activities and Allow Reports on unless you have a strong reason to disable them.

  3. Add the first master-detail field (primary master)

    Fields and Relationships, New, Master-Detail Relationship. Pick the parent that should drive sharing inheritance and default report grouping. Set sharing to Read/Write. This is the primary master and the choice is permanent for this object.

  4. Add the second master-detail field (secondary master)

    Repeat the process for the second parent. The two master-detail fields together form the many-to-many bridge. Both fields are required on every junction record, and the Object Manager will not let you save a junction without populating both.

  5. Add the relationship-specific attributes

    This is where the junction earns its keep. Add status, role, start date, end date, percentage allocation, primary flag, or whatever attribute belongs to the A-to-B pairing rather than to either parent. These fields are why a junction beats a multi-select picklist for serious data modeling.

  6. Build a custom report type that joins all three objects

    Setup, Report Types, New. Pick the junction as the primary object and add both masters as related. This is the only way to produce a single report that shows columns from all three with correct join semantics. Do this early, even if no report consumer has asked for it yet.

  7. Test uniqueness, sharing, and cascade behavior

    Create test junctions with the same pair to verify your dedup logic fires. Log in as users in different roles and confirm visibility matches expectation through both masters. Delete one parent and confirm every junction referencing it disappears, then restore from Recycle Bin and confirm reattachment.

First Master-Detail Fieldremember

Parent object reference to the primary master. Required on every record. Drives sharing inheritance and default report grouping.

Second Master-Detail Fieldremember

Parent object reference to the secondary master. Required on every record. Completes the many-to-many bridge.

Custom Object Name and API Nameremember

Name the junction descriptively. Course_Enrollment__c tells a future admin what it does. Generic names like Junction__c create technical debt immediately.

Gotchas
  • Using lookup instead of master-detail on either side leaves the junction without an Owner field. Only System Administrators see records, and your users assume the data is missing. Always use master-detail twice.
  • The first master-detail you create becomes the primary master permanently. You cannot swap primary and secondary later without recreating the object and migrating data. Choose the security-sensitive parent first.
  • Deleting either parent deletes every junction record referencing it. Plan archival carefully if either side needs to retain historical join data after the parent is removed.
  • Junction objects have no Owner field of their own. Manual sharing and queues do not apply at the junction level. Access is controlled entirely by the two masters and their sharing rules.
  • Standard report types treat each junction as a child of one parent only. Cross-parent reports require a custom report type, and stakeholders always discover this need after the first dashboard request.

See the full Junction Object entry

Junction Object includes the definition, worked example, deep dive, related terms, and a quiz.