Home › Salesforce (Apex / LWC) › Salesforce Apex + LWC AGENTS.md
Salesforce Apex + LWC AGENTS.md
AGENTS.md for Salesforce DX projects: bulkified Apex, governor limits, sharing and CRUD/FLS, Lightning Web Components, and sf CLI tests.
AGENTS.mdSalesforce (Apex / LWC)
How to use
Save this as AGENTS.md in your repository root, commit it, and your agent will pick it up automatically. Edit the commands to match your project.
Note: Review and test before use. Provided as is, without warranty. See Terms.
AGENTS.mdDownload # AGENTS.md: Salesforce DX project (Apex + LWC)
## Commands
- Deploy to a scratch org or sandbox: `sf project deploy start --source-dir force-app`
- Apex tests: `sf apex run test --test-level RunLocalTests --code-coverage --result-format human --wait 20`
- LWC unit tests: `npm run test:unit` (sfdx-lwc-jest) · lint: `npm run lint` · format: `npx prettier --check "force-app/**/*.{cls,trigger,js,html}"`
- Never deploy to production from an agent session.
## Code map
`force-app/main/default/` → `classes/` (Apex), `triggers/`, `lwc/`, `objects/`, `permissionsets/`, `flows/`. API version lives in `sfdx-project.json`; match it in new `-meta.xml` files.
## Apex rules
- Bulkify everything: triggers and services take `List<SObject>`/`Map<Id, SObject>`. No SOQL or DML inside loops.
- One trigger per object that delegates to a handler class; no logic in the trigger body.
- Respect sharing and security: classes declare `with sharing` (or `inherited sharing`), queries use `WITH USER_MODE` or `Security.stripInaccessible`, DML uses `insert as user` where appropriate.
- Use bind variables in SOQL; never build dynamic SOQL from user input without `String.escapeSingleQuotes` or `Database.queryWithBinds`.
- Async work via Queueable (chainable) or Batch Apex for large volumes; `@future` only for simple callouts.
- Callouts through Named Credentials; no endpoints or secrets in code or custom labels.
- Custom exceptions per domain; never swallow exceptions with empty `catch`.
## LWC rules
- Wire adapters or imperative Apex calls with `@AuraEnabled(cacheable=true)` for reads. Use Lightning Data Service (`lightning/uiRecordApi`) before custom Apex.
- `@api` for public props, reactive fields by default; no direct DOM manipulation outside `this.template.querySelector`.
- Show errors with `ShowToastEvent` and `reduceErrors`-style helpers.
## Tests
- Every Apex class gets a `@IsTest` class with `Test.startTest()/stopTest()`, bulk (200 records) and negative cases, `System.runAs` for permission checks, and asserts via `Assert.areEqual`. Don't use `SeeAllData=true`.
- Aim for meaningful coverage (75% org minimum is a floor, not the goal).
## Done
Local Apex tests and Jest tests pass in a scratch org, and deploy validates with no errors.