Skip to main content

Separation of Concerns

Explore practical guides and implementation patterns for this topic.

Posts

Apex & Dev

Why Trigger Handlers Break at Scale in Salesforce

💬 In plain words: A trigger handler is a hallway, not a house. When a Salesforce org scales up, if you don't have separate rooms (layers) for your logic, everything piles into that one hallway. Eventually, you get a massive, fragile class where every new change risks breaking everything else. Layered architecture exists precisely to solve this problem. 📌 Example: In Year 1, your AccountTriggerHandler is a tidy 300 lines of code. By Year 4, it has swollen to 5,000 lines. Fourteen different developers are committing changes to it, and every deployment seems to break an unrelated feature. You've hit the "God-handler" ceiling. You need to split it up—because a hallway can't hold an entire house. 🎬 Real-Life Example: The 5,000-Line Hallway Imagine a class called DeliveryTriggerHandler that is five years old and 5,000 lines long. The Old/Bad Way: Every new feature just became one more method stuffed into the same c...
Read article
Salesforce Basics

The Salesforce Separation of Concerns: Understanding Service, Domain, and Selector Layers

In plain words: Large enterprise organizations split their Apex code into specific functional "floors" or layers. The Service layer holds the business logic, the Domain layer handles object-specific rules, the Selector layer manages all queries, and the Unit of Work executes database commits safely. This is known as "Separation of Concerns." As Salesforce implementations grow, unstructured Apex quickly turns into spaghetti code. When multiple developers write SOQL queries and DML statements randomly across triggers, batch classes, and LWC controllers, the system becomes fragile and unscalable. To solve this, developers use the Enterprise Design Patterns (often modeled via the fflib architecture) to give every piece of logic a strict, predictable home. Key Points: The Four Layers of Apex The core concept is to assign exactly one job to each layer of your code. Selector Layer: The absolute only place where SOQL queries live. D...
Read article