From sfdx-iq
Create, review, refine, or debug Apex classes (service, selector, controller, utility, domain)
How this command is triggered — by the user, by Claude, or both
Slash command
/sfdx-iq:apex-class [--new | --review | --refine | --bug-fix] [ClassName or path]This command is limited to the following tools:
The summary Claude sees in its command listing — used to decide when to auto-load this command
# /apex-class Work with Salesforce Apex classes across the full development lifecycle using `--new`, `--review`, `--refine`, or `--bug-fix`. ## Usage --- ## --new: Create a New Apex Class ### Gather Requirements Ask the user: 1. What is the class name and its role? (Service, Selector, Controller, Utility, Domain, Batch — see patterns below) 2. What object(s) does it operate on? 3. What methods are needed? (brief description of each) 4. Any specific patterns? (TriggerHandler framework, Callable, Invocable, etc.) ### Apex Class Patterns **Service Class** — Business operations **Sel...
Work with Salesforce Apex classes across the full development lifecycle using --new, --review, --refine, or --bug-fix.
/apex-class --new Create a new Apex class + test class
/apex-class --review Review an existing class for quality, security, governor limits
/apex-class --refine Modify an existing class (add feature, change behavior)
/apex-class --bug-fix Diagnose and fix a bug in an existing class
Ask the user:
Service Class — Business operations
public with sharing class AccountService {
public static void processAccounts(List<Id> accountIds) {
List<Account> accounts = AccountSelector.getById(accountIds);
// business logic
update accounts;
}
}
Selector Class — Centralized SOQL queries (never in service/domain classes)
public inherited sharing class AccountSelector {
public static List<Account> getById(Set<Id> accountIds) {
return [SELECT Id, Name, Industry, OwnerId
FROM Account
WHERE Id IN :accountIds
WITH USER_MODE];
}
}
Controller (Apex for LWC) — @AuraEnabled methods only; thin layer
public with sharing class AccountController {
@AuraEnabled(cacheable=true)
public static List<Account> getAccounts(Id ownerId) {
return AccountSelector.getByOwner(new Set<Id>{ownerId});
}
}
Domain Class — Object-specific logic without DML/SOQL
public with sharing class AccountDomain {
public static void setDefaultIndustry(List<Account> accounts) {
for (Account acc : accounts) {
if (String.isBlank(acc.Industry)) acc.Industry = 'Other';
}
}
}
Security:
with sharing, without sharing, or inherited sharing — never omitWITH USER_MODE or WITH SECURITY_ENFORCED in SOQLSecurity.stripInaccessible() before insert/updateDatabase.queryWithBinds() — never string concatenationBulkification:
List<SObject> or Set<Id> — never single recordsWHERE Id IN :recordIdsSOQL:
start()WHERE Id IN :idSet for selective, indexed filteringError Handling:
Database.insert(records, false) for partial success when appropriateNaming:
AccountService, AccountSelector, AccountController)getAccountsByIndustry, submitForApproval)MAX_RETRY_COUNT)Test Class Standards:
<ClassName>Test@TestSetup for data setupTest.startTest() / Test.stopTest() around the unit being testedCreate both files:
force-app/main/default/classes/<ClassName>.cls — implementationforce-app/main/default/classes/<ClassName>.cls-meta.xml — metadata with correct API versionforce-app/main/default/classes/<ClassName>Test.cls — test classforce-app/main/default/classes/<ClassName>Test.cls-meta.xmlSummarize what was generated: methods created, design decisions made, test scenarios covered.
git diff --name-only HEAD for changed .cls filesPass the identified files to the apex-code-reviewer agent with the full review workflow.
The review covers:
Output: Severity-grouped findings (CRITICAL → HIGH → MEDIUM → LOW) with file:line references and fixes.
--refine <ClassName or path> provided, use thatAsk the user:
/apex-class --new
/apex-class --new AccountService with getAccountsByIndustry and updateIndustry methods
/apex-class --review
/apex-class --review force-app/main/default/classes/OpportunityService.cls
/apex-class --refine AccountService add a method to bulk-update AnnualRevenue
/apex-class --bug-fix AccountService.processAccounts throws NullPointerException on update
npx claudepluginhub bhanu91221/sfdx-iq --plugin sfdx-iq