Reference: AT4DX Quick Lookup
Metadata Custom Objects
| Type | Purpose | Key Fields |
|---|---|---|
ApplicationFactory_SelectorBinding__mdt |
Maps SObjectType → selector class | BindingSObject__c, To__c, Priority__c |
ApplicationFactory_DomainBinding__mdt |
Maps SObjectType → domain constructor | BindingSObject__c, To__c |
ApplicationFactory_ServiceBinding__mdt |
Maps interface → service implementation | BindingInterface__c, To__c, Priority__c |
ApplicationFactory_UnitOfWorkBinding__mdt |
Defines SObjects and DML insertion order | BindingSObject__c, BindingSequence__c |
SelectorConfig_FieldSetInclusion__mdt |
Injects fieldset fields into selector queries | BindingSObject__c, FieldsetName__c |
DomainProcessBinding__mdt |
Wires a Criteria or Action to an SObject + trigger operation (or method token) | Type__c, ClassToInject__c, RelatedDomainBindingSObject__c, ProcessContext__c, TriggerOperation__c, OrderOfExecution__c, ExecuteAsynchronous__c, IsActive__c |
DomainProcessBinding__mdt — Key Fields
| Field | Meaning |
|---|---|
Type__c |
Criteria or Action (the only two values) |
ClassToInject__c |
The Apex class to instantiate |
RelatedDomainBindingSObject__c |
SObject API name the binding applies to (e.g. Account) |
ProcessContext__c |
TriggerExecution (driven automatically by the domain trigger) or DomainMethodExecution (invoked by a token) |
TriggerOperation__c |
For TriggerExecution: Before_Insert, After_Update, etc. |
DomainMethodToken__c |
For DomainMethodExecution: the token passed to processDomainLogicInjections(token, ...) |
OrderOfExecution__c |
Number(4,2) (so 0.00–99.99). The integer part (0–99) is the sequence group; the two decimals order bindings within a type |
ExecuteAsynchronous__c |
Boolean. When true (and the action implements IDomainProcessQueueableAction), the action runs in a queueable |
LogicalInverse__c |
Boolean. When true, a criteria excludes its matches instead of keeping them |
IsActive__c |
Boolean. Inactive bindings are ignored |
There is no
ProcessName__c,ClassName__c, orOrder__cfield, and noAsyncActiontype. Async is theExecuteAsynchronous__cboolean on a normalAction. Within a context + SObject + operation, bindings are grouped into sequences byInteger.valueOf(OrderOfExecution__c); in each sequence all Criteria chain-filter the record set, then all Actions run on the survivors.
Key Classes and Interfaces
Application Factories
| Call | What It Returns | Backed By |
|---|---|---|
Application.Selector.newInstance(SObjectType) |
IApplicationSObjectSelector |
ApplicationFactory_SelectorBinding__mdt + fieldset injection |
Application.Domain.newInstance(List<SObject>) |
IApplicationSObjectDomain |
ApplicationFactory_DomainBinding__mdt |
Application.Domain.newInstance(Set<Id>) |
IApplicationSObjectDomain |
Same — loads records via the Selector factory first |
Application.Domain.newInstance(List<SObject>, SObjectType) |
IApplicationSObjectDomain |
Same — when the list's type can't be inferred |
Application.Service.newInstance(Type) |
The interface you specify | ApplicationFactory_ServiceBinding__mdt |
Application.UnitOfWork.newInstance() |
IApplicationSObjectUnitOfWork |
ApplicationFactory_UnitOfWorkBinding__mdt |
Base Classes and Interfaces
| Class / Interface | Layer | What It Does |
|---|---|---|
ApplicationSObjectSelector |
AT4DX | Extends fflib_SObjectSelector, adds fieldset injection via SelectorConfig_FieldSetInclusion__mdt |
IApplicationSObjectSelector |
AT4DX | Interface for all AT4DX selectors |
AbstractSelectorMethodInjectable |
AT4DX | Base for package-specific list queries invoked with selectInjection(...) |
AbstractSelectorQueryLocatorInjectable |
AT4DX | Base for package-specific QueryLocator queries invoked with selectQueryLocatorInjection(...) |
ApplicationSObjectDomain |
AT4DX | Extends fflib_SObjectDomain, adds DomainProcessCoordinator hooks |
IApplicationSObjectDomain |
AT4DX | Interface for all AT4DX domains |
IApplicationSObjectUnitOfWork |
AT4DX | Interface for the DI-enabled unit of work |
IDomainProcessCriteria |
AT4DX | Interface for Criteria classes — setRecordsToEvaluate + run |
DomainProcessAbstractAction |
AT4DX | Base class for Actions — override runInProcess, read the protected this.records / this.uow fields |
DomainProcessCoordinator |
AT4DX | Orchestrates Criteria → Action execution. Invoked automatically by ApplicationSObjectDomain for trigger operations |
Code Patterns: Quick Snippets
Call a Common Selector Method
List<Account> accounts = AccountsSelector.newInstance().selectById(accountIds);
Call an Injected Selector Method
SelectLargeAccountsSelectorMethod.Parameters params =
new SelectLargeAccountsSelectorMethod.Parameters();
params.minimumRevenue = 1000000;
List<Account> largeAccounts = AccountsSelector.newInstance().selectInjection(
SelectLargeAccountsSelectorMethod.class,
params
);
Call a Service
Services are a triad (interface, static entry point, registered impl). Callers use the static entry point:
SalesAccountsService.processAccountUpdates(accountIds);
Get a Unit of Work and Commit
IApplicationSObjectUnitOfWork uow = Application.UnitOfWork.newInstance();
uow.register(accounts);
uow.register(newOpportunity, Opportunity.AccountId, parentAccount);
uow.commitWork();
Define a Criteria
public class MyAccountCriteria implements IDomainProcessCriteria {
private List<Account> records;
public IDomainProcessCriteria setRecordsToEvaluate(List<SObject> records) {
this.records = (List<Account>) records;
return this;
}
public List<SObject> run() {
List<SObject> matched = new List<SObject>();
for (Account a : records) {
if (/* your condition */) { matched.add(a); }
}
return matched;
}
}
Define an Action
public class MyAccountAction extends DomainProcessAbstractAction {
public override void runInProcess() {
// this.records holds the criteria-filtered set; this.uow may be null in trigger context.
for (SObject record : this.records) {
((Account) record).SomeField__c = 'newValue';
}
// In a before-trigger the mutation above persists with no DML.
// If a UoW was supplied (e.g. DomainMethodExecution), stage DML with it:
if (this.uow != null) {
this.uow.register(this.records);
}
}
}
Wire a Trigger Process (no domain code)
For trigger-context processing you do not call the coordinator — ApplicationSObjectDomain does. You only deploy bindings:
DomainProcessBinding__mdt
Type__c=Criteria ClassToInject__c=MyAccountCriteria
RelatedDomainBindingSObject__c=Account ProcessContext__c=TriggerExecution
TriggerOperation__c=After_Update OrderOfExecution__c=10.10 IsActive__c=true
DomainProcessBinding__mdt
Type__c=Action ClassToInject__c=MyAccountAction
RelatedDomainBindingSObject__c=Account ProcessContext__c=TriggerExecution
TriggerOperation__c=After_Update OrderOfExecution__c=10.20 IsActive__c=true
Invoke the Coordinator Yourself (DomainMethodExecution only)
// Inside one of your own domain methods (not a trigger override):
public void recalc(IApplicationSObjectUnitOfWork uow) {
// 'MyMethodToken' matches DomainProcessBinding__mdt.DomainMethodToken__c
getDomainProcessCoordinator().processDomainLogicInjections('MyMethodToken', uow);
}
Mock Selector in Tests
fflib_ApexMocks mocks = new fflib_ApexMocks();
IAccountsSelector mockSel =
(IAccountsSelector) mocks.mock(IAccountsSelector.class);
mocks.startStubbing();
// Required: Application.Selector.setMock() asks the mock for its SObjectType.
mocks.when(mockSel.sObjectType()).thenReturn(Account.SObjectType);
mocks.when(mockSel.selectById(accountIds)).thenReturn(fakeAccounts);
mocks.stopStubbing();
Application.Selector.setMock(Account.SObjectType, mockSel);
Mock UnitOfWork in Tests
fflib_ApexMocks mocks = new fflib_ApexMocks();
IApplicationSObjectUnitOfWork mockUow =
(IApplicationSObjectUnitOfWork) mocks.mock(IApplicationSObjectUnitOfWork.class);
Application.UnitOfWork.setMock(mockUow);
// Later verify:
((IApplicationSObjectUnitOfWork) mocks.verify(mockUow, 1))
.register(expectedRecords);
Mock DomainProcessBindings in Tests
List<DomainProcessBinding__mdt> bindings = new List<DomainProcessBinding__mdt>{
new DomainProcessBinding__mdt(
Type__c = 'Criteria', ClassToInject__c = 'MyAccountCriteria',
RelatedDomainBindingSObject__c = 'Account', ProcessContext__c = 'TriggerExecution',
TriggerOperation__c = 'After_Update', OrderOfExecution__c = 10.10, IsActive__c = true),
new DomainProcessBinding__mdt(
Type__c = 'Action', ClassToInject__c = 'MyAccountAction',
RelatedDomainBindingSObject__c = 'Account', ProcessContext__c = 'TriggerExecution',
TriggerOperation__c = 'After_Update', OrderOfExecution__c = 10.20, IsActive__c = true)
};
DomainProcessCoordinator.setMockDomainProcessBindings(bindings);
Common Errors and Solutions
Could not find binding for [SObjectType or Interface]
Cause: No active ApplicationFactory_*__mdt record matches the type being requested.
Steps:
- Query for the record:
SELECT * FROM ApplicationFactory_SelectorBinding__mdt WHERE BindingSObject__c = 'Account' - Verify
IsActive__c = true(if the field exists in your version) - Confirm
BindingSObject__corBindingInterface__cmatches exactly (e.g.,AccountnotAccount__c) - Confirm the metadata record was deployed:
sf project deploy startand check deploy results
Fields not appearing in query results
Cause: SelectorConfig_FieldSetInclusion__mdt record missing or FieldSet not found.
Steps:
- Verify the
SelectorConfig_FieldSetInclusion__mdtrecord was deployed - Verify the FieldSet exists on the SObject in the scratch org:
sf data query --query "SELECT Id, FieldsetName__c FROM SelectorConfig_FieldSetInclusion__mdt WHERE BindingSObject__c='Account'" - Verify the FieldSet's fields are accessible to the running user (field-level security)
Actions not running during domain processing
Cause: DomainProcessBinding__mdt records missing, inactive, or not matching the SObject/operation.
Steps:
- Query bindings:
SELECT Type__c, ClassToInject__c, ProcessContext__c, TriggerOperation__c, OrderOfExecution__c, IsActive__c FROM DomainProcessBinding__mdt WHERE RelatedDomainBindingSObject__c = 'Account' - Verify
IsActive__c = true - Confirm
ProcessContext__candTriggerOperation__cmatch the trigger event (e.g.TriggerExecution/After_Update) - Check
OrderOfExecution__c— its integer part groups Criteria with the Actions meant to run on their output. Mutually-exclusive criteria must use different integer parts (separate sequences) - For a sequence with Actions but no qualifying records, the Actions are skipped (the coordinator only runs Actions when the criteria-filtered set is non-empty)
System.LimitException: Too many queueable jobs added to the queue
Cause: Async action trying to enqueue a queueable in a context where a job is already enqueued.
Options:
- Use Platform Events instead of Queueable for reliable async decoupling
- Check
Limits.getQueueableJobs()before enqueuing:if (Limits.getQueueableJobs() < Limits.getLimitQueueableJobs()) { ... } - See Subscription-Based-Platform-Events for the at4dx platform event distribution pattern
Type not visible or Type cannot be constructed
Cause: To__c field in a binding metadata record points to a class that is not visible (global/public) or does not implement the expected interface.
Steps:
- Confirm the class is
publicorglobal - Confirm the class implements the correct interface or extends the correct base class
- For domain bindings, confirm
To__cpoints to theConstructorinner class, not the domain class itself (e.g.,AccountDomain.Constructor)
Framework Reference
- Frameworks — fflib, force-di, and at4dx core
- Environment-Setup — setting up a scratch org
- Subscription-Based-Platform-Events — cross-package event distribution via Platform Events
- Test-Data-Builder-Field-Injection — injecting required field values into test data
Document Index
| Document | Topic |
|---|---|
| Getting Started | Orientation, audience, and prerequisites |
| DI Concepts | What dependency injection is, how AT4DX implements it |
| Architecture Layers | Package layering and code placement decisions |
| Application Factory Injection | Four factories in detail with full configuration examples |
| Selector Field Injection | Fieldset-driven field inclusion across packages |
| Selector Method Injection | Package-specific list and QueryLocator methods on the singular SObject selector |
| Domain Process Injection | DomainProcessCoordinator, IDomainProcessCriteria, DomainProcessAbstractAction |
| Multi-App – Single Org Example | Complete end-to-end implementation across Sales, Marketing, and Service |
| Testing Patterns | Unit tests, integration tests, mock cheat sheet |