Getting started with APX
apx is a Salesforce CLI plugin that generates Apex Enterprise Patterns code (fflib or at4dx) for an SObject: Domain, Selector, Service, and Unit of Work. This guide walks you through a first run.
Install
Use Node.js 22 or later. The plugin uses the exact version of apx-core pinned in package.json.
sf plugins install @syntax-syllogism/apx@x.y.zOr build from source (see Contributing):
git clone git@github.com:Syntax-Syllogism/apxcd apxyarn && yarn buildnode ./bin/dev.js apx generate --helpThe basics
Most apx generate commands that use an org need two things:
- A flavor. Pass exactly one of
--at4dxor--fflib. The flavor decides which templates are used for every file the command creates: the interface and implementation shape, the binding metadata format, and the base classes. - A target.
--target-organd--sobjectmake APX describe a live SObject, so it can use the real field names and know whether the object is custom or standard.
Some commands work offline. The AT4DX-only action, criteria, selector method, and selector field-injection commands take the SObject API name as plain text. service also works offline and takes --service-basename instead of an SObject.
Every command accepts --dry-run (render and validate, write nothing) and --output-path (default generated-files, relative to the Salesforce project root).
Your first run
Generate an AT4DX selector for Account:
sf apx generate selector --target-org myOrg --sobject Account --at4dxAPX describes Account in myOrg, then writes a selector interface, an implementation, a unit test, and (for AT4DX) a SelectorConfig binding custom metadata record under generated-files/.
To see what it would write first, add --dry-run:
sf apx generate selector --target-org myOrg --sobject Account --at4dx --dry-run --jsonWant to be prompted instead? Add -i. APX asks for the values you left out, shows a summary, and asks you to confirm before it writes anything:
sf apx generate selector -i --target-org myOrg --sobject AccountSee Interactive generation for the details.
Several layers at once
The bare apx generate command builds more than one layer from a single SObject describe, so it makes one API call:
sf apx generate --target-org myOrg --sobject Account \ --selector --domain --unit-of-work --at4dxSet at least one of --selector, --domain, or --unit-of-work, or the command fails. See Aggregate generation for how binding sequence and prefix apply.
Offline scaffolding
Some artifacts don’t need an org:
# An action class and its AT4DX domain-process bindingsf apx generate action -s Account -c DefaultAccountSloganBasedOnNameAction
# A field set and binding for an existing selectorsf apx generate selector field-injection -s Account --fields Name,IndustrySee Offline domain-process generation for how --trigger-operation, --order, and --process-name combine into the binding’s developer name.
Next steps
- Command details: flavors, naming and prefixes, binding sequence, domain-process metadata, and dry-run and overwrite behavior.
- Dead-code analysis: find classes nothing references.
- Every flag: the Commands section of the README, or
--helpon any command.