Enforces Salesforce Apex governor limits, naming conventions, bulkification, and security rules in classes, triggers, and batch jobs during writing or review.
How this skill is triggered — by the user, by Claude, or both
Slash command
/salesforce-claude-code:sf-apex-constraintsThis skill is limited to the following tools:
The summary Claude sees in its skill listing — used to decide when to auto-load this skill
This skill auto-activates when writing, reviewing, or modifying any Apex class, trigger, or batch job. It enforces governor limits, naming conventions, bulkification rules, and security requirements for all Apex artifacts.
This skill auto-activates when writing, reviewing, or modifying any Apex class, trigger, or batch job. It enforces governor limits, naming conventions, bulkification rules, and security requirements for all Apex artifacts.
Hard rules that every Apex class, trigger, and batch job must satisfy. Violations here cause governor failures, security review rejections, or production incidents. Reference files contain the full data; this skill contains only the enforcement rules.
@../_reference/GOVERNOR_LIMITS.md @../_reference/NAMING_CONVENTIONS.md @../_reference/SECURITY_PATTERNS.md @../_reference/DEPRECATIONS.md
Exception — masks programming bugs (NullPointerException, TypeException); catch specific types onlywithout sharing; always declare with sharing, without sharing, or inherited sharing explicitlywithout sharing on user-facing classes — bypasses record-level security; must be with sharingglobal access modifier — locks managed package API surface; use public unless building a package APISystem.debug in production code — fills debug logs, can expose sensitive dataDatabase.queryWithBinds()Database.SaveResult — partial-success DML silently drops failures; always inspect every resultelement.innerHTML = userInput — XSS vulnerability; use textContent or sanitized componentsList<sObject> as a parameter type — loses type information; use concrete types like List<Account>strName, lstAccounts) — use descriptive camelCase names insteadwith sharing by default — only use without sharing with a documented justificationWITH USER_MODE for SOQL, AccessLevel.USER_MODE for DML on user-facing operations{Object}TriggerHandler)Service, Selector, TriggerHandler, Batch, Job, Scheduler, Controller, Test, ExceptionTest (not prefix) — AccountServiceTest, not TestAccountServicetest{Method}_{scenario}_{expectedResult}Exception throwsLimits.getQueries(), Limits.getCpuTime(), etc.String.join() for string building — not concatenation in loops (heap + CPU cost)?. (null-safe navigation) for parent relationship fields| Anti-Pattern | Problem | Correct Pattern |
|---|---|---|
| SOQL in loop | Exceeds per-transaction SOQL limit (see @../_reference/GOVERNOR_LIMITS.md) | Query once, store in Map |
| DML in loop | Exceeds per-transaction DML limit (see @../_reference/GOVERNOR_LIMITS.md) | Collect records, single DML after loop |
| Nested loops for matching | CPU time exhaustion (O(n^2)) | Map/Set lookup (O(1)) |
| String concat in loop | Heap growth + CPU waste | List<String> + String.join() |
| SELECT * (all fields) | Heap exhaustion | SELECT only required fields |
| No sharing keyword | Silent without sharing default | Explicit with sharing declaration |
| Missing CRUD/FLS check | Security review failure | WITH USER_MODE / AccessLevel.USER_MODE |
| Dynamic SOQL via concat | SOQL injection | Bind variables / queryWithBinds() |
Catching Exception | Masks real bugs | Catch specific exception types |
| Ignoring SaveResult | Silent data loss | Inspect every Database.SaveResult |
| Hardcoded IDs | Breaks across orgs | SOQL / Custom Metadata lookup |
sf-apex-best-practices — implementation examples for the rules above (class organization, error handling, collection patterns)npx claudepluginhub jiten-singh-shahi/salesforce-claude-code --plugin salesforce-claude-codeGenerates production-grade Apex classes with Service-Selector-Domain layering, sharing models, and async patterns (Queueable, Batchable, Schedulable). Static code generation without org connection.
Generates, refactors, and reviews Apex classes including service, selector, domain, triggers, batch, queueable, and REST resources. Includes test generation.
Writes and debugs Apex, builds Lightning Web Components, optimizes SOQL, and sets up Salesforce DX/CI/CD pipelines for CRM customization and integration.