AI-assisted Salesforce delivery
How I build on Salesforce when an AI assistant writes the code: context, agents and guardrails, and the hierarchy that settles who wins.
This is the development architecture of my Salesforce base template: the repository every new project starts from. It describes how the work gets done when an AI assistant writes the code under human supervision, and it is verified against the real state of that repository, not against what I would like it to be.
The principle behind it and the limit I acknowledge are in the introduction to Articles.
The governing principle
The person directs, the AI executes. But the AI is only trustworthy when it has context and when its output is validated.
Three layers come out of that, and none of them works alone: without context the AI improvises, without agents there is no structured execution, and without guardrails any hallucination reaches production.
| Layer | What it settles | With what |
|---|---|---|
| 1 · Context | The rules the AI is obliged to read before generating anything | One source-of-truth document and a set of skills per artefact type |
| 2 · Agents | Who does the work, and with how much context | Claude Code as the orchestrator, specialised subagents, SDD and persistent memory |
| 3 · Guardrails | What validates the output before it is accepted | ESLint over the JavaScript, PMD over the Apex, Salesforce Code Analyzer over both |
1. Context: the rules the AI reads
One documentary hierarchy, with no ambiguity about what wins. Top to bottom:
CLAUDE.md— holds no rules. It only redirects toAGENTS.md.AGENTS.md— the single source of truth: architecture, commands, conventions. In theAGENTS.mdformat, which any tool that supports it can read, not only the one I use.- Rules per artefact type (
apex-rules.md,lwc-rules.md,metadata-rules.md) — the detail. Against the document above, the specific rule wins. - Shared generic skills — Salesforce best practice that depends on no project. A local repository rule beats the shared one when they clash.
- The linters’ configuration —
eslint.config.jsand the PMD ruleset. The final authority on style and quality, above any document.
Configuration beating the document is not a detail of ordering: it is the only thing that actually runs. A document can go stale without anyone noticing; a ruleset cannot.
The absolute rule
Before generating any file — Apex, LWC, metadata, test — the AI has to read the skill that applies to it. No exception for urgency, simplicity or familiarity with the pattern. Not one line of code before the rules have been read.
It is the rule that holds up the whole context layer, and it is also the easiest to skip, because skipping it produces no visible error.
2. Agents: who executes
I work with Claude Code, Anthropic’s CLI, on Claude Opus 5. The main thread writes code, orchestrates the subagents and runs the validation tools, but its real job is not to do all of it itself.
The delegation test
One question decides: does this inflate my context without need?
| Action | Inline | Delegated |
|---|---|---|
| Read 1–3 files to decide or verify | ✅ | — |
| Read four or more files to understand | — | ✅ |
| Write one file, mechanically, already knowing what | ✅ | — |
| Write new logic across several files | — | ✅ |
Check state (git, gh) |
✅ | — |
| Run tests or builds | — | ✅ |
Each subagent starts with clean context and a narrow role, does its work and returns only the conclusion, not a dump of the files it read.
The subagent panel
| Subagent | Role | Model |
|---|---|---|
Explore |
Broad read-only search; returns conclusions | Sonnet |
Plan |
Designs implementation plans and spots the critical files | Sonnet |
general-purpose |
Multi-step tasks and complex searches | Sonnet |
review-risk · -readability · -reliability · -resilience |
A review panel by dimension: security, readability, reliability, resilience | Sonnet |
jd-judge-a · jd-judge-b · jd-fix-agent |
Blind dual review, and a fix for what both judges confirm | Sonnet |
sdd-* |
One subagent per phase of the spec-driven flow | Per phase |
Reviews are delegated on purpose: an agent that looks at the diff without the author’s framing finds what the author can no longer see.
How the model is assigned
The orchestrating thread runs on Claude Opus 5. When it delegates, the model is sized to the demand of the task: general, non-SDD delegation uses Sonnet by default, and each SDD phase uses its own. If the assigned model is unavailable, Sonnet takes its place.
This is not token thrift, it is fit: reading code and writing in a structured way do not demand what deciding an architecture demands, and paying for Opus to copy and close a change does not make it better.
Skills: the mandatory context, written down
Skills are what makes the absolute rule real. Each covers one artefact type and fixes naming, security, test structure and conventions. When the work crosses categories — an LWC calling Apex — all the ones involved are read.
| Skill | What it fixes |
|---|---|
apex-rules.md |
Mandatory header, naming, reserved words, bulkified SOQL and DML with WITH USER_MODE, with sharing, try/catch in @AuraEnabled, mock pattern, tests at 85 % |
lwc-rules.md |
No logic in the HTML, lwc:if/lwc:else, mandatory Custom Labels (zero hardcoded text), @wire versus imperative calls, SLDS 2 with styling hooks |
metadata-rules.md |
Conventions for metadata XML, objects, fields and Custom Metadata Types |
Each one also forwards to the final authority: the Apex one requires reading the PMD ruleset and the LWC one requires reading eslint.config.js before writing. The rules are not duplicated, they are centralised, precisely so they cannot diverge.
Shared skills: from the repository to a plugin
The generic skills no longer live in the repository. They used to be copied into .claude/skills/; today they ship as a Claude Code plugin from a private marketplace of my own.
The reason is maintenance: every project then shares exactly the same version of each skill, and a correction is published once instead of being replicated repository by repository. The files are never copied into the working tree, they are cached outside Git, and skills are invoked by name, never by path.
The wiring lives in .claude/settings.json, which is versioned: a clone of the repository comes configured, and all that is needed is access to the plugin repository.
Two traps I walked into, worth anticipating:
- Plugins are linked at session start. After an update you have to restart, or the open session keeps seeing the previous registry and it looks as if the plugin fails to load.
- If the skills do not appear, check repository access first, not the configuration.
Changing a shared skill is done in the plugin repository, not the project’s. And because that repository is shared, it cannot contain a single org name or client artefact: that is part of the contract, not a precaution.
The analyser as the single entry point
dx-code-analyzer-run orchestrates Salesforce Code Analyzer across all of its engines — PMD for Apex, ESLint for JavaScript, CPD, RetireJS, Flow, SFGE, ApexGuru — and handles the full cycle: scan, filter, explain rules and apply the engine’s own deterministic fixes, never AI-generated and always confirmed.
It supports --engine, --category, --severity and --diff, which scans only what changed against the base. All interaction with results goes through packaged scripts, never direct reads of the JSON, which can exceed 10 MB.
Its installation flags medium risk in dependency analysis. The reason is not malicious code — these are official Salesforce scripts — but that it ships scripts with write permission: the one that applies fixes can modify code. The mitigation ships inside: the skill itself requires confirmation before touching anything.
Who wins when conventions clash
The official Apex generators carry conventions that contradict my template’s: Assert.* versus System.assertEquals, a test data factory versus inline @TestSetup, naming, batch size, coverage target.
The decision is made: my rules win. But the mechanism changed. Shared skills no longer carry a preamble imposing any project’s conventions — being shared, they cannot. The repository imposes the authority instead: the absolute rule requires reading apex-rules.md before generating Apex, and that file is local, so it always wins. The official skills are used for their workflow — discover, generate, run the analyser, generate tests, report — not for their conventions.
What improved: a plugin update no longer overwrites anything in the repository, because the project rules live outside the skill.
What is still fragile: enforcement is documentary, not mechanical. It depends on the AI reading the file, not on a gate that verifies it.
Metadata splits differently. The four XML generators — objects, fields, tabs and Lightning Pages — do carry an adaptation, but not as a preamble: it is a section at the end of their own SKILL.md, maintained inside the plugin repository, holding the durable conventions of the base template (API version, SFDX structure, file templates, dependency order when generating). They are the template’s conventions, identical across every project and belonging to no one’s org, which is why they travel with the shared skill and no longer have to be reapplied after each update. The trade-off is that changing them means publishing a new plugin version.
What stays in the repository
Not everything moved to the plugin. Some skills stay because their divergence between projects is deliberate: each project specialises them to the org it works with. They are the per-artefact rules, Flow generation from natural language, walking the UI in a real browser, test plan generation, and Markdown-to-Word conversion with a branded template.
When a local skill and a plugin skill share a name, the local one wins.
For LWC the full precedence, highest authority first, is: eslint.config.js and the PMD ruleset; then lwc-rules.md, this project’s conventions; and below them the plugin’s generators and SLDS skills, which fill in what lwc-rules.md does not detail — accessibility, test patterns, SLDS 2.
One frozen skill, and why I say so
Flow generation from natural language is installed but inert. It does not generate the XML itself: it delegates, compulsorily, to a Salesforce MCP tool through a three-step pipeline, and that MCP server is not connected in the project. The real blocker runs deeper: even connected, the first step of the pipeline is not supported today, with an open issue in Salesforce’s repository.
Decision made: freeze it until that is resolved or the alternative MCP server matures out of beta. Meanwhile Flows are created the way they always were. Editing existing Flows and the orchestration level do work: only creation from scratch is blocked.
I say so because an inventory that lists only what works is not an inventory, it is a brochure.
SDD: structured planning
For substantial changes I do not jump straight to code. SDD — spec-driven development — breaks the change into phases with explicit dependencies, each run by a dedicated subagent and each producing a versioned artefact.
| Phase | What it produces | Model | Why |
|---|---|---|---|
sdd-explore |
Reads the code and compares approaches | Sonnet | Structural, not architectural |
sdd-propose |
Intent, scope, approach | Opus | Architectural decisions |
sdd-spec |
Requirements and scenarios | Sonnet | Structured writing |
sdd-design |
Architecture decisions | Opus | Architecture decisions |
sdd-tasks |
An ordered work checklist | Sonnet | Mechanical breakdown |
sdd-apply |
The implementation | Sonnet | Implementation |
sdd-verify |
Validation against the spec | Sonnet | Validation against the spec |
sdd-archive |
Close and persist | Haiku | Copy and close |
The artefacts are stored by the chosen backend: Engram — persistent memory, no files, fast for individual work — OpenSpec — versioned files in the repository, committable and shareable, with Git history — or both at once, which is files for the team plus Engram for recovery between sessions.
Engram: the memory that outlives the session
A context window runs out; Engram does not. It is the persistent memory system that stores decisions, conventions, fixed bugs and discoveries, so the next session does not start blind. It also survives a context compaction, which is when it matters most.
Saving is proactive: it does not wait to be asked. It persists the moment an architecture or convention decision is made, when a bug is fixed — with its root cause — when a gotcha or edge case turns up, and when I state a preference or a constraint.
| Tool | What it does |
|---|---|
mem_save |
Persist knowledge |
mem_search |
Find prior work |
mem_context |
Recover the recent history |
mem_session_summary |
Session close |
The rule that keeps it useful rather than a dumping ground: a memory is for the future self, not for the user. Saving is not replying.
3. Guardrails: what validates the output
There is no automatic gate, and it is worth saying
This template installs no Git hooks: no pre-commit, no lint over staged files, no commit message validation, no AI reviewer. A git commit validates nothing on its own. Validation is explicit, and whoever is developing — or the assistant — triggers it before committing.
| Command | What it does | Authority |
|---|---|---|
npm run lint |
ESLint over the LWC JavaScript | eslint.config.js |
npm run format · format:check |
Prettier over CSS, HTML, JS, JSON, Markdown and YAML | .prettierrc |
npm run test:unit · :coverage |
LWC Jest tests | — |
sf code-analyzer run |
PMD, ESLint, CPD, RetireJS and Flow over Apex and JavaScript | the analyser’s configuration |
npm run release |
Versioning and changelog | the versioning configuration |
I use Conventional Commits because the changelog is generated from them, but nothing validates that automatically: it is the author’s discipline.
With no automatic gate, the real guardrail is the analyser run before handing work over, plus human review. A derived project that wants a pre-commit block has to add the hook explicitly.
ESLint: sole authority over the JavaScript
ESLint 9 flat config, extending Salesforce’s recommended LWC configuration and adding rules of its own. Some of the rules below are inherited from the preset and do not appear written in the file: to see the resolved configuration, npx eslint --print-config <file>.
| Rule | Severity | What it requires |
|---|---|---|
no-var |
error | Never var; let or const |
prefer-const |
error | const when the variable is not reassigned |
eqeqeq |
error | Strict comparison always |
no-unused-vars |
error | Nothing declared and unused |
no-undef |
error | No references to undefined symbols |
no-duplicate-imports |
error | One import per module |
@lwc/lwc/no-api-reassignments |
error | Do not reassign @api properties |
@lwc/lwc/no-document-query |
error | No document.querySelector; use this.template |
@lwc/lwc/no-inner-html |
error | No innerHTML, because of XSS risk |
@lwc/lwc/valid-api · no-leading-uppercase-api-name |
error | Valid @api properties, in camelCase |
no-console |
warning | Avoid console.* in production |
prefer-template |
warning | Template literals instead of concatenation |
no-param-reassign |
warning | Do not mutate function parameters |
PMD: authority over the Apex
The ruleset covers six categories; priority marks severity, from P1 critical to P5 minor.
| Category | Notable rules | Priority |
|---|---|---|
| Performance | OperationWithLimitsInLoop: no SOQL or DML in loops |
P1 |
| Security | ApexSOQLInjection, ApexXSSFromURLParam, ApexInsecureEndpoint |
P1 |
| Error Prone | EmptyCatchBlock, AvoidHardcodingId, AvoidDirectAccessTriggerMap |
P1 |
| Best Practices | ApexUnitTestClassShouldHaveAsserts, ApexUnitTestShouldNotUseSeeAllDataTrue |
P1 |
| Best Practices | AvoidLogicInTrigger: the logic belongs in the handler |
P5 |
| Design | ExcessiveClassLength, CognitiveComplexity, TooManyFields |
P2 |
| Code Style | ClassNamingConventions, IfStmtsMustUseBraces, method and variable naming |
P1–P2 |
| Documentation | ApexDoc: document public and global members |
P3 |
AvoidLogicInTrigger is not a decorative rule: it reinforces the project’s real pattern, where each trigger is a single line delegating to a factory and the logic lives in the handlers.
The full path of a change
- Context. The AI reads the source-of-truth document and the skill that applies, by the absolute rule, before touching code.
- Planning. For large changes, SDD breaks the work into phases and the subagents execute. Memory keeps the decisions.
- Generation. Apex with
with sharingand bulkified SOQL; LWC with Custom Labels and SLDS 2. - Explicit validation. Lint, tests and the analyser over what was touched. Nobody triggers them for me.
- Review. Review subagents over the diff, plus human review.
- Commit. A Conventional Commits message. With no hooks the commit always passes; quality is guaranteed by steps 4 and 5.
Where the risk is. With no automatic gate, skipping step 4 produces no visible error: just unvalidated code on the main branch. It is the most fragile point of this setup, and I would rather have it written down than pretend it does not exist.
Known documentation debt
This architecture is verified against the real state of the repository. These are the points where the documentation runs behind the code, or can start to:
- No automatic quality gate. There are no Git hooks. Apex depends on PMD and the analyser being run by hand, and JavaScript on ESLint the same way. It is the setup’s most important limitation.
- Convention enforcement is documentary. My rules prevailing over the official skills’ depends on the AI reading them, not on a mechanism that verifies it.
- The generic skills are no longer in the repository. Listing the skills directory no longer shows the full catalogue, only what is local. The shared set is queried through the CLI.
- Updating the plugin requires restarting the session. An update with the session open has no effect and looks like a loading failure.
- Skill names change. The rename to Salesforce’s official naming already invalidated one version of this document. When in doubt, what the CLI returns wins.
- Cross references by path break with every migration. One skill pointed in three places at a folder that ceased to exist when that dependency moved to the plugin. It is fixed, and it is the pattern to watch: skills are invoked by name, without a path, precisely so they do not depend on where they live.
The structure and the patterns — the layers, the delegation, the authority hierarchy — do not age. The concrete inventories — skill names, configuration paths, versions — do, and fast. In case of conflict, the code and the authoritative configuration files win.
What the knowledge base covers
This page is about how I work. What Salesforce documents about building with AI on its own platform — what its AI assistant writes for you, where your code and org context go, and what checks the result before you deploy it — is a separate page, “AI-assisted development”, in the knowledge base, under Salesforce Platform and its development section. It is not published yet, so it is named here without a link.