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.

More: all Salesforce (Apex / LWC) rules · all AGENTS.md rules

Related rules

REST API design AGENTS.md

AGENTS.md for designing consistent HTTP/JSON APIs: resource naming, status codes, errors, pagination, and versioning.

AGENTS.mdAPI design

Blazor (.NET 10) AGENTS.md

AGENTS.md for Blazor Web Apps on .NET 10: render modes, components, forms and validation, state, and bUnit tests.

AGENTS.md.NET / ASP.NET Core

Celery background jobs AGENTS.md

AGENTS.md for Celery 5 task queues in Python/Django: idempotent tasks, retries, time limits, and safe enqueueing.

AGENTS.mdPython

Deno 2 AGENTS.md

AGENTS.md for Deno 2 projects: deno.json tasks, JSR and npm imports, permissions, and built-in tooling.

AGENTS.mdDeno

Effect TypeScript AGENTS.md

AGENTS.md for TypeScript codebases built on Effect: typed errors, services and Layers, Schema validation, resource safety, and @effect/vitest tests.

AGENTS.mdEffect (TypeScript)

Express 5 API AGENTS.md

AGENTS.md for Express 5 REST APIs in TypeScript with zod validation, error middleware, and supertest.

AGENTS.mdNode.js / TypeScript

Get the best new AI prompts every week

One short email a week: the best new prompts and rules for ChatGPT, Claude, Gemini, Midjourney, Cursor and more, plus what changed in the tools. Free, unsubscribe anytime.

Finishes on our newsletter page at beehiiv (opens in a new tab). Or subscribe directly.