Apex Code
Write custom Apex classes, triggers, and batch jobs. Describe what you need in plain English and AI builds production-ready Salesforce code.
Skill Details
Install this skill
Works with
Use this skill when the user needs production Apex: new classes, triggers, selectors, services, async jobs, invocable methods, test classes, or evidence-based review of existing .cls / .trigger code.
When This Skill Owns the TaskWorkflow
Use sf-apex when the work involves:
- Apex class generation or refactoring
- trigger design and trigger-framework decisions
@InvocableMethod, Queueable, Batch, Schedulable, or test-class work- review of bulkification, sharing, security, testing, or maintainability
Delegate elsewhere when the user is:
Required Context to Gather FirstWorkflow
Ask for or infer:
- class type: trigger, service, selector, batch, queueable, schedulable, invocable, test
- target object(s) and business goal
- whether code is net-new, refactor, or fix
- org / API constraints if known
- expected test coverage or deployment target
Before authoring, inspect the project shape:
- existing classes / triggers
- current trigger framework or handler pattern
- related tests, flows, and selectors
- whether TAF is already in use
Recommended Workflow
1. Discover local architecture
Check for:
- existing trigger handlers / frameworks
- service-selector-domain conventions
- related tests and data factories
- invocable or async patterns already used in the repo
2. Choose the smallest correct pattern
| Need | Preferred pattern | |
|---|---|---|
| simple reusable logic | service class | |
| query-heavy data access | selector | |
| single object trigger behavior | one trigger + handler / TAF action | |
| Flow needs complex logic | @InvocableMethod | |
| background processing | Queueable by default | |
| very large datasets | Batch Apex or Database.Cursor patterns | |
| repeatable verification | dedicated test class + test data factory | |
| Anti-pattern | Why it blocks | |
| SOQL in loops | governor-limit failure | |
| DML in loops | governor-limit failure | |
| missing sharing model | security / data exposure risk | |
| hardcoded IDs | deployment and portability failure | |
empty catch blocks | silent failure / poor observability | |
| string-built SOQL with user input | injection risk | |
| tests without assertions | false-positive test suite | |
| Scenario | Default | |
| standard async work | Queueable | |
| very large record processing | Batch Apex | |
| recurring schedule | Scheduled Flow or Schedulable | |
| post-job cleanup | Finalizer | |
| long-running Lightning callouts | Continuation | |
| Need | Delegate to | Reason |
| describe objects / fields first | sf-metadata | avoid coding against wrong schema |
| seed bulk or edge-case data | sf-data | create realistic test datasets |
| run Apex tests / fix failing tests | sf-testing | execute and iterate on failures |
| deploy to org | sf-deploy | validation and deployment orchestration |
| build Flow that calls Apex | sf-flow | declarative orchestration |
| build LWC that calls Apex | sf-lwc | UI/controller integration |
| Score | Meaning | |
| 120+ | strong production-ready Apex | |
| 90–119 | good implementation, review before deploy | |
| 67–89 | acceptable but needs improvement | |
| < 67 | block deployment |
More in Apex & Flow
Debug Logs
Read and analyze Salesforce debug logs. Paste the error, AI finds the root cause and tells you exactly what to fix.
Deployments
Deploy metadata between Salesforce orgs. AI handles the CLI commands, validation, and flags the things that could go wrong.
Flow Builder
Build record-triggered and screen flows. Describe your business logic and AI generates the flow structure with best practices built in.
Navigate Apex & Flow