.cursor/skills/sf-apex-constraints/SKILL.md
Enforce Apex governor limits, naming, bulkification, and security rules. Use when writing or reviewing ANY Apex class, trigger, or batch job. Do NOT use for LWC, Flow, or Visualforce.
npx skillsauth add jiten-singh-shahi/salesforce-claude-code sf-apex-constraintsInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
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)development
Update Salesforce platform reference docs with latest release features and deprecation announcements. Use when SessionStart hook warns docs are outdated or a new Salesforce release has shipped. Do NOT use for Apex or LWC development.
development
Use when syncing documentation after Salesforce Apex code changes. Update README, API docs, and deploy metadata references to match the current org codebase.
development
Use when managing context during long Salesforce Apex development sessions. Suggests manual compaction at logical intervals to preserve deploy and org context across phases.
tools
Visualforce development — pages, controllers, extensions, ViewState, JS Remoting, LWC migration. Use when maintaining VF pages, building PDFs, or planning VF-to-LWC migration. Do NOT use for LWC, Aura, or Flow.