Skip to main content
Separation of Concerns on the Salesforce platform

The libraries that will allow your Salesforce org to scale however you need it to.

Twenty chapters on how to implement The Apex Common Library, The Apex Mocks Library and Force DI in your Salesforce org. Every chapter has a video. Everything here is open source forever.

  • Written for Apex developers and architects
  • 9h 6m of video
How the Separation of Concerns layers work togethershowing domain
delegatescallsinvokesqueriesregistersSOQLcommitTrigger4 lines, foreverControllerLWC · batch · APIDomainch 09–11Servicech 07–08Selectorch 12–14Unit of Workch 05–06delegatescallsinvokesqueriesregistersSOQLcommitTrigger4 lines, foreverControllerLWC · batch · APIDomainch 09–11Servicech 07–08Selectorch 12–14Unit of Workch 05–06
Layer

Domain

Represents the behavior of a single SObject. It often houses validations, default values and any other object-specific automations.

The rule

A domain class should only represent the behavior of a single object in your org, not multiple objects. Behavior representative of multiple objects should live in the service layer.

Chapters
All twenty chapters

Read it in order, or jump to the layer you're interested in.

Find out exactly what you need to implement the Apex Common Library, fast.

20 of 20 chapters

Introduction

01022 chapters
01Introduction to the Separation of Concerns Design PrincipleAn explanation of the Separation of Concerns Design Principle and why it is valuable to implement in any codebase.6 min readvideo 18:42Standard02Introduction to the Apex Common LibraryAn overview of the tools available with the Apex Common Library.5 min readvideo 15:20Standard

The Application class

03042 chapters
03The Factory Method PatternCreating an object without naming the concrete class you get back.6 min readvideo 19:55Pattern04The fflib_Application ClassThe abstract factory class that the other layers rely on.22 min readvideo 32:15Annotated

The Unit of Work

05062 chapters
05The Unit of Work PatternBatching DML into one atomic, correctly ordered transaction.4 min readvideo 16:08Pattern06The fflib_SObjectUnitOfWork ClassHow to utilize the Unit of Work with Apex Common Library.9 min readvideo 28:47Standard

The Service layer

07082 chapters
07The Service LayerThe layer where your business logic lives.10 min readvideo 24:08Standard08Implementing the Service Layer with the Apex Common LibraryHow to setup your service classes with the Apex Common Library in mind.14 min readvideo 35:22Implementation

The Domain layer

09113 chapters
09The Template Method PatternDefine the skeleton up top and let the subclass fill in the steps.4 min readvideo 14:36Pattern10The Domain LayerA representation of an object/database table that incorporates both its behavior and data.8 min readvideo 21:04Standard11Implementing The Domain Layer with the Apex Common LibraryHow to implement the Domain Layer with the assistance of the Apex Common Library.13 min readvideo 38:50Implementation

The Selector layer

12143 chapters
12The Builder PatternA creational design pattern that allows for the step-by-step construction of complex objects.9 min readvideo 17:29Pattern13The Selector LayerYour org's SOQL queries live here.7 min readvideo 27:31Standard14Implementing the Selector Layer with the Apex Common LibraryHow to implement the Selector Layer using the Apex Common Library.16 min readvideo 36:14Implementation

The Apex Mocks library

15173 chapters
15The Difference Between Unit Tests and Integration TestsMocks are fast and isolated. Integration tests are slow and real. You need both.4 min readvideo 13:52Standard16Unit Test Mocks with Separation of ConcernsWhy SoC is the thing that makes true unit testing possible.11 min readvideo 26:40Standard17Implementing Mock Unit Tests with the Apex Mocks LibraryHow to implement unit tests using the Apex Mocks Library33 min readvideo 41:19Implementation

Dependency Injection with Force DI

18203 chapters
18Dependency Injection and Inversion of ControlAsk for the interface, let configuration decide the class.8 min readvideo 21:07Pattern19Implementing Force DI Bindings, Modules and ProvidersWiring up di_Binding__mdt records, modules and providers to resolve dependencies at runtime.15 min readvideo 64:42Implementation20TDD and Mocking with Force DITrue unit tests with Test.createStub and runtime binding overrides.11 min readvideo 31:36Implementation