
Sf Apex
Generate or review Salesforce Apex—classes, triggers, async jobs, and tests—with a structured 150-point quality bar.
Overview
sf-apex is an agent skill for the Build phase that generates and reviews Salesforce Apex with 150-point scoring across eight categories.
Install
npx skills add https://github.com/jaganpro/sf-skills --skill sf-apexWhat is this skill?
- 150-point scoring across 8 review categories for Apex and triggers
- Covers triggers, services, selectors, Queueable, Batch, Schedulable, and @InvocableMethod
- Explicit delegation to sf-lwc, sf-flow, sf-soql, and sf-deploy for non-Apex work
- Enforces bulkification, sharing, security, and test-class expectations
- Triggers on .cls and .trigger creation, review, or repair
Adoption & trust: 1.4k installs on skills.sh; 418 GitHub stars; 3/3 security scanners passed (skills.sh audits).
What problem does it solve?
You need Salesforce Apex or triggers that pass security and bulk rules but lack a consistent review framework or test strategy.
Who is it for?
Indie consultants and solo builders implementing Salesforce backend automation with triggers, services, and required test classes.
Skip if: LWC-only UI work, Flow-only orchestration, standalone SOQL scripts, or deployments with zero Apex changes.
When should I use this skill?
User writes, reviews, or fixes Apex classes, triggers, test classes, batch/queueable/schedulable jobs, or touches .cls/.trigger files.
What do I get? / Deliverables
You get production-oriented Apex—or a scored review with fixes—and hand deployment to sf-deploy when the org push is next.
- Apex classes or triggers with framework-appropriate structure
- Test classes aligned to coverage goals
- Review notes tied to 150-point / 8-category scoring
Recommended Skills
Journey fit
Build is the canonical phase because the skill produces and refactors server-side Salesforce logic, not go-to-market or ops monitoring. Backend subphase fits Apex, triggers, selectors, and platform services as core server code on Salesforce.
How it compares
Use as an Apex generator and reviewer, not as a replacement for sf-flow or sf-lwc when the task is declarative or client-side.
Common Questions / FAQ
Who is sf-apex for?
Builders and admins writing Salesforce server code—classes, triggers, async jobs, invocables, and tests—who want structured generation and review.
When should I use sf-apex?
Use it in Build backend work whenever you create, fix, or audit .cls or .trigger files, bulk-safe triggers, or Apex test classes; do not use it for LWC, Flow XML, or deploy-only tasks.
Is sf-apex safe to install?
It guides code that runs in customer orgs with elevated data access—review the Security Audits panel on this page and follow least-privilege sharing in generated Apex.
Workflow Chain
Then invoke: sf deploy
SKILL.md
READMESKILL.md - Sf Apex
# sf-apex: Salesforce Apex Code Generation and Review 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 Task 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: - editing LWC JavaScript / HTML / CSS → [sf-lwc](../sf-lwc/SKILL.md) - building Flow XML or Flow orchestration → [sf-flow](../sf-flow/SKILL.md) - writing SOQL only → [sf-soql](../sf-soql/SKILL.md) - deploying or validating metadata to orgs → [sf-deploy](../sf-deploy/SKILL.md) --- ## Required Context to Gather First 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 | ### 3. Author with guardrails Generate code that is: - bulk-safe - sharing-aware - CRUD/FLS-safe where applicable - testable in isolation - consistent with project naming and layering ### 4. Validate and score Evaluate against the 150-point rubric before handoff. ### 5. Hand off deploy/test next steps When org validation is needed, hand off to: - [sf-testing](../sf-testing/SKILL.md) for test execution loops - [sf-deploy](../sf-deploy/SKILL.md) for deploy / dry-run / verification --- ## Generation Guardrails Never generate these without explicitly stopping and explaining the problem: | 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 | Default fix direction: - query once, operate on collections - use `with sharing` unless justified otherwise - use bind variables and `WITH USER_MODE` where appropriate - create assertions for positive, negative, and bulk cases See [references/anti-patterns.md](references/anti-patterns.md) and [references/security-guide.md](references/security-guide.md). --- ## Hig