Skip to main content

Junction Objects & Schema Limits

 

Junction Objects & Schema Limits

💬 In plain words:  A junction object is a small 'middle table' with two master-details, used when both sides can have many of each other (Students ↔ Courses → Enrollment). It's how you build many-to-many on the platform.

📌 Example:  Students and Courses: one student takes many courses, one course has many students. Create Enrollment with two Master-Details — the junction. Ravi's enrollment in 'Apex 101' is one Enrollment record carrying grade and enrollment date.

🧠 The middle table:  Many-to-many = two master-details meeting in a small middle object. Students and Courses meet in Enrollment; Skyline's Parcels and Routes meet in a Stop.

🔗 Connects to:  the master-detail choice both legs depend on   ·   one busy parent record creates data skew at scale

Concept

A junction object models many-to-many. It is a custom object with two Master-Detail relationships.

•  The first Master-Detail you create is the primary one.

•  The junction takes its look and feel, its ownership and its sharing from that parent.

•  Deleting either master deletes the junction rows, though undelete behaves differently depending on which side went first.

•  A junction is also where the data about the relationship itself lives: dates, roles, status on the association.

🧭 360 Card — Junction Objects & Schema Limits 

Nobody picks the primary master by ticking a box. It is decided by the order you create the fields: the first master-detail you add wins. That is why you cannot see it easily in Setup — you check it with Workbench or the Metadata API. To swap it, you convert both relationships down to lookup and then back to master-detail in the order you want. So decide the order before you build, not after.

Rule:  many-to-many means one small middle object carrying two Master-Details.

Gain:  a real row for the relationship. It holds its own fields: grade, date, quantity. And it rolls up to both sides.

Price:  the junction inherits sharing from both parents. A user needs access to both, so access gets harder to reason about, not easier.

Limits:  exactly two Master-Details, so a third leg must be a Lookup. The first relationship you create is primary: it drives look and feel and detail sharing. Delete both masters and undeleting one will not bring the junction rows back.

Mirror — two lookups instead:  independent sharing and no cascade, but you lose roll-ups on both legs and you own the cleanup.

Later:  this is what makes the "keep the slots free" rule in 2.1 matter. Spend a Master-Detail on convenience and the junction is no longer possible.

At volume:  a junction sits under two parents, so it is twice as exposed to parent-lock contention.

⚠ INTERVIEW TRAP:  The primary master-detail is decided by CREATION ORDER, not by a setting. Create them in the wrong order and you must convert both to lookup and back to fix it.

Core Q&A

Q: How does sharing work on a junction object, and why does the order of creating the two Master-Details matter?

🎯 Say this first:  The junction inherits sharing from BOTH masters. A user needs access to both. The FIRST master-detail you create is the primary. It controls look-and-feel and detail sharing.

A: The junction inherits sharing from BOTH masters.

•  A user needs at least read access on both parents to see the junction record. And you configure the required access level on each Master-Detail relationship.

•  The first relationship you create is the primary one. It controls owner inheritance and the detail-page association.

•  Common mistake: creating them in the wrong order.

•  The only fix is to delete and recreate the relationship, and on a populated object that means data surgery. So pick the primary side deliberately — usually the parent that matters more to the business.

Follow-ups (scenario-based)

Q1: What happens to junction records if one master record is deleted and then undeleted?

A1: Delete a master and the junction rows cascade-delete with it.

•  Undelete that master and they come back. But if BOTH masters were deleted, undeleting one does not bring the junction records back.

•  Once the second master goes, they are gone for good.

•  That asymmetry matters in data-retention conversations, and this is a classic 'have you actually run this' probe.

Q2: You are hitting the 2-Master-Detail-per-object ceiling on a schema with three-way associations. How do you model it?

A2: You have three options. Make the third relationship a required Lookup on the junction.

•  You lose cascade delete and roll-ups on that leg, but the association is still queryable.

•  Or split into two junctions, chained through a middle object.

•  Or step back and ask whether that third 'relationship' is really an attribute — a picklist or a reference field — rather than a full participant.

•  The architect answer adds the reporting consequence.

•  Standard report types traverse only so much relationship depth.

•  A model that is normalized but deep may need custom report types, or a flattened reporting object.

Popular Posts

Must-listen songs for developers

Here are some must-listen songs for developers: "Strobe" by deadmau5 . This electronic dance music (EDM) track is perfect for getting into a flow state. The repetitive beat and simple melody are easy to focus on, and the overall mood of the song is upbeat and motivating.  "Viva la Vida" by Coldplay . This rock song has a soaring melody and powerful lyrics that can inspire you to stay focused and productive. The song's message of hope and resilience is perfect for those times when you're feeling stuck or discouraged.  "Code Monkey" by Jonathan Coulton . This tongue-in-cheek song is a hilarious and accurate portrayal of the life of a software developer. The lyrics are catchy and the song's upbeat tempo will make you want to get up and dance.  "The Sound of Silence" by Simon & Garfunkel . This classic folk song is perfect for those times when you need to focus and concentrate. The song's slow tempo and haunting melody will h...

Uninstall all Windows 10 default apps using Powershell

Here is script to uninstall all windows 10 default modern apps. This script uninstalls xbox, xbox Game bar, Xbox App,Xbox Gaming Overlay, Get started etc from your computer. No need to run one by one commands Just copy below script, run  powershell as administrator and paste script and press enter . It will automatically uninstall all default programs.  If you do not  want to uninstall some apps than just remove " "  line from script. $packages = @( "7EE7776C.LinkedInforWindows" "C27EB4BA.DropboxOEM" "Microsoft.3DBuilder" "Microsoft.Microsoft3DViewer"

Salesforce LWC Code for Multi-Select Lookup

Introduction: In Salesforce Lightning Web Components (LWC), implementing a multi-select lookup field can enhance the user experience and provide greater flexibility for selecting multiple related records. In this blog post, we will walk through the process of creating a multi-select lookup field using LWC. We will cover the required code snippets and provide step-by-step instructions to help you implement this functionality in your Salesforce org.

Apex Test Class Examples for @HttpPost Exposed WebService Class

Introduction: In Salesforce, the Apex programming language allows you to create powerful web services that can be exposed to external systems for data integration. One common scenario is using the @HttpPost annotation to create a custom RESTful web service. In this blog post, we'll walk through some examples of how to write effective test classes for an @HttpPost exposed web service class in Salesforce. Writing comprehensive test classes ensures that your code is robust, functional, and ready for deployment.

How to Save Quote PDF, Send PDF, Preview PDF in salesforce with custom functionality

Want to develop custom pdf viewer, save pdf in quote pdf related List and Send quote to customer on button click when quote is custom in salesforce . These functionality are standard from salesforce. but you can develop these functionality custom in salesforce. Here is the solution:- Custom button to save Quote PDF and send PDF  Step 1:-  First Create Two custom button. which will used for PDF preview and Save quote pdf in quotes pdf related list.                               1. PDF preview Button                              2. Save & Send Quote Button Replace "Your VF page here" to Your quote PDF cuatom page. Step 2:-  PDF preview button   pdf preview button will display the pdf's preview in standard format of salesforce. So you need to set the  following configuration (In picture). After that you have ...

Setup vs Non-Setup Objects (Mixed DML)

Core Platform & Fundamentals Module map MODULE 1 root: 'Who can do what, on which objects/fields?' ├─ Setup vs non-setup (transaction rules) ├─ Profile + Perm Sets + PSG (access = union) ├─ Licensing (the ceiling) ├─ CRUD/FLS (objects & fields) └─ Reports/Dashboards (who sees what data) 1.1 Setup vs Non-Setup Objects (Mixed DML) 💬 In plain words:   Salesforce keeps 'admin' records (like User, Group) and 'business' records (like Account, Case) in two separate rooms. One transaction cannot write to both rooms at once — that error is Mixed DML. The fix: do the second write in a separate async step. Concept

Unleashing the Power of Flow Orchestrator in Salesforce: Streamlining Business Processes

Introduction: Salesforce Flow Orchestrator is a powerful tool that enables businesses to automate and streamline complex business processes within the Salesforce platform. With its intuitive visual interface, advanced workflow capabilities, and seamless integration with other Salesforce features, Flow Orchestrator revolutionizes how organizations manage and optimize their processes. In this blog post, we will explore the features, benefits, and potential of Flow Orchestrator in driving operational efficiency and productivity. 1. Simplifying Complex Business Processes: Flow Orchestrator empowers business users to design and execute complex workflows without the need for extensive coding or technical expertise. Its visual interface allows users to create dynamic flows, define decision points, and automate repetitive tasks, all while maintaining a clear and intuitive process design. 2. Enhanced Automation with Conditional Logic: Flow Orchestrator offers advanced conditional logic c...