Skip to main content

fflib

Explore practical guides and implementation patterns for this topic.

Posts

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