/salesforce-development:salesforce-apex-qualityfrom salesforce-development
Reviews and generates Salesforce Apex code with guardrails for bulk safety, CRUD/FLS enforcement, SOQL injection prevention, and governor limit compliance. Use when reviewing triggers, handlers, batch jobs, or test classes.
Ships in salesforce-development. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Apply Apex guardrails to code generation and review so Salesforce code remains bulk-safe, secure, testable, and deployable under governor limits.
Scan every Apex class, trigger, and test before declaring it acceptable. SOQL/DML bulk-safety is an automatic fail area.
| Pattern | Required action |
|---|---|
[SELECT or [SELECT ...] inside a for loop | Refactor: collect IDs, query once outside the loop, then use maps or grouped lists. |
Database.query inside a loop | Refactor to a single parameterized or whitelisted query outside the loop. |
insert, update, delete, upsert, or merge inside a loop | Collect records and perform one DML statement outside the loop. |
| Per-record trigger logic or query/update loops | Move business logic to a handler that accepts collections. |
// NEVER — causes LimitException at scale
for (Account a : accounts) {
List<Contact> contacts = [SELECT Id FROM Contact WHERE AccountId = :a.Id];
update a;
}
// ALWAYS — collect, query once, update once
Set<Id> accountIds = new Map<Id, Account>(accounts).keySet();
Map<Id, List<Contact>> contactsByAccount = new Map<Id, List<Contact>>();
for (Contact c : [SELECT Id, AccountId FROM Contact WHERE AccountId IN :accountIds]) {
if (!contactsByAccount.containsKey(c.AccountId)) {
contactsByAccount.put(c.AccountId, new List<Contact>());
}
contactsByAccount.get(c.AccountId).add(c);
}
update accounts;
Every class must declare sharing intent explicitly. Undeclared sharing inherits from the caller and creates unpredictable behaviour.
| Declaration | Use when |
|---|---|
public with sharing class Foo | Default for service, handler, selector, and controller classes. |
public without sharing class Foo | Only for required elevated behavior such as system-level logging or trigger bypass; require a code comment explaining why. |
public inherited sharing class Foo | Framework entry points that should respect the caller's sharing context. |
Apex code that reads or writes records on behalf of a user must enforce object and field access. Treat missing CRUD/FLS. as a deployment blocker. UI-facing, REST-facing, and @InvocableMethod code must use CRUD/FLS checks; trusted internal services may rely on with sharing only when the call path is controlled.
if (!Schema.sObjectType.Contact.fields.Email.isAccessible()) {
throw new System.NoAccessException();
}
List<Contact> contacts = [SELECT Id, Email FROM Contact WHERE AccountId = :accId WITH USER_MODE];
List<Contact> contacts2 = Database.query('SELECT Id, Email FROM Contact', AccessLevel.USER_MODE);
| Query shape | Rule |
|---|---|
| Static SOQL | Use bind variables such as :userInput. |
| Dynamic SOQL values | Bind values where possible; never concatenate raw user input. |
| Dynamic field or sort names | Validate user-controlled values against a whitelist before adding to the query string. |
// NEVER — concatenates user input into SOQL
String soql = 'SELECT Id FROM Account WHERE Name = \'' + userInput + '\'';
// ALWAYS — bind variable
List<Account> rows = [SELECT Id FROM Account WHERE Name = :userInput];
Set<String> allowedFields = new Set<String>{'Name', 'Industry', 'AnnualRevenue'};
if (!allowedFields.contains(userInput)) {
throw new IllegalArgumentException('Field not permitted: ' + userInput);
}
PNB coverage is mandatory: Positive, Negative, and Bulk.
| Path | Required evidence |
|---|---|
| Positive | Expected input produces exact expected field values, counts, or return values. |
| Negative | Nulls, invalid inputs, empty collections, and errors throw the right type/message and do not mutate records. |
| Bulk | Insert, update, or delete 200–251 records in one test transaction and assert all records process without governor failures. |
@isTest(SeeAllData=false)
private class AccountServiceTest {
@TestSetup
static void makeData() {
// Create all test data here; use a factory if one exists.
}
@isTest
static void givenValidInput_whenProcessAccounts_thenFieldsUpdated() {
List<Account> accounts = [SELECT Id FROM Account LIMIT 10];
Test.startTest();
AccountService.processAccounts(accounts);
Test.stopTest();
List<Account> updated = [SELECT Status__c FROM Account WHERE Id IN :accounts];
Assert.areEqual('Processed', updated[0].Status__c, 'Status should be Processed');
}
}
Trigger checklist:
with sharing unless elevated access is documented.| Old pattern | Modern replacement |
|---|---|
if (obj != null) { x = obj.Field__c; } | x = obj?.Field__c; |
x = (y != null) ? y : defaultVal; | x = y ?? defaultVal; |
System.assertEquals(expected, actual) | Assert.areEqual(expected, actual) |
System.assert(condition) | Assert.isTrue(condition); migrate System.assert and System.assertEquals to Assert.isTrue and Assert.areEqual. |
[SELECT ... WHERE ...] with no sharing context | [SELECT ... WHERE ... WITH USER_MODE] |
| Pattern | Action |
|---|---|
escape="false" on user data in Visualforce | Remove it; auto-escaping enforces XSS prevention. |
Empty catch block | Add logging and appropriate re-throw or error handling. |
| Test with no assertion | Add meaningful Assert.* calls. |
Hardcoded record ID such as '001...' | Replace with queried or inserted test data. |
Inline API names to preserve: Test.startTest() and Test.stopTest() isolate governor counters for async and bulk assertions.
## Apex quality result
**Status:** pass | fix required | blocked
**Scope:** `<files/classes/triggers reviewed>`
| Area | Severity | Evidence | Required fix |
| --- | --- | --- | --- |
| Bulk safety | `<High|Medium|Low>` | `<line or snippet>` | `<fix>` |
### Tests
- Positive path: <covered|missing>
- Negative path: <covered|missing>
- Bulk path: <covered|missing, record count>
### Validation
- Sharing declaration: <pass|fail>
- CRUD/FLS: <pass|fail|not applicable>
- SOQL injection: <pass|fail>
Database.query, Insert/update/delete operations, or DML appears inside a loop.with sharing, without sharing, or inherited sharing with justification where needed.WITH USER_MODE, or AccessLevel.USER_MODE.Assert.* calls.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
salesforce, apex, governor-limits, bulk-safety, crud-fls, soql-injection
3 skills in this plugin
/salesforce-component-standardsApply Salesforce UI component standards for Lightning Web Components, Aura, Visualforce, SLDS 2, WCAG 2.1 AA, secure Apex access, component communication, XSS, CSRF, FLS/CRUD, view state, and Jest tests. Use when building or reviewing Salesforce LWC, Aura components, Visualforce pages, or Apex controllers used by UI components./salesforce-flow-designSalesforce Flow architecture decisions, flow type selection, bulk safety validation, fault handling, automation density, Screen Flow UX, and deployment safety. Use this skill when designing or reviewing Record-Triggered, Screen, Autolaunched, Scheduled, or Platform Event flows before activation or deployment.npx claudepluginhub gbb-acelerators/awesome-harness-primitives --plugin salesforce-developmentOther plugins' skills for the same job