Sf apex

From Jaganpro/sf-skills · View interactive version

Sf apex is an AI agent skill from the GitHub repository Jaganpro/sf-skills. Generates and reviews Salesforce Apex code with 150-point scoring. TRIGGER when: user writes, reviews, or fixes Apex classes, triggers, test classes, batch/queueable/schedulable jobs, or touches .cls/.trigger files. DO NOT TRIGGER when: LWC JavaScript (use sf-lwc), Flow XML (use sf-flow), SOQL-only

How to use this skill

Skill file

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:

Delegate elsewhere when the user is:


Required Context to Gather First

Ask for or infer:

Before authoring, inspect the project shape:


Recommended Workflow

1. Discover local architecture

Check for:

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:

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:


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:

See references/anti-patterns.md and references/security-guide.md.


High-Signal Build Rules

Trigger architecture

Async choice

| 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 |

Testing minimums

Use the PNB pattern for every feature:

Modern Apex expectations

Prefer current idioms when available:


Output Format

When finishing, report in this order:

  1. What was created or reviewed
  2. Files changed
  3. Key design decisions
  4. Risk / guardrail notes
  5. Test guidance
  6. Deployment guidance

Suggested shape:

Apex work: <summary>
Files: <paths>
Design: <pattern / framework choices>
Risks: <security, bulkification, async, dependency notes>
Tests: <what to run / add>
Deploy: <dry-run or next step>

LSP Validation Note

This skill supports an LSP-assisted authoring loop for .cls and .trigger files:

Full guide: references/troubleshooting.md


Cross-Skill Integration

| 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 |


Reference Map

Start here

High-signal checklists

Specialized patterns

Troubleshooting / validation


Score Guide

| Score | Meaning |

|---|---|

| 120+ | strong production-ready Apex |

| 90–119 | good implementation, review before deploy |

| 67–89 | acceptable but needs improvement |

| < 67 | block deployment |

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.