/sf-core:platform-apex-generatefrom Salesforce — Socle
Generates, refactors, and reviews Apex classes including service, selector, domain, batch, queueable, schedulable, invocable, DTO, utility, interface, abstract, exception, REST resource, and triggers.
Ships in Salesforce — Socle. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Use this skill for production-grade Apex: new classes, selectors, services, async jobs,
invocable methods, and triggers; and for evidence-based review of existing .cls OR .trigger.
Gather or infer before authoring:
Defaults unless specified:
with sharing (see sharing rules per type below)public (use global only when required by managed packages or @RestResource)66.0 (minimum version)If the user provides a clear, complete request, generate immediately without unnecessary back-and-forth.
All steps are sequential. Do not skip, merge, or reorder. If blocked, stop and ask for missing context. If not applicable, mark N/A with a one-line justification in the report.
Discover project conventions
integration-apex-symbol-table-query (API v67.0+); if unavailable, read the sourceChoose the smallest correct pattern (see Type-Specific Guidance below)
Review templates and assets
assets/ before authoring (see Type-Specific Guidance for the file mapping)references/ example exists for the type, read it as a concrete style guideplatform-apex-test-generate skillAuthor with guardrails -- apply every rule in the Rules section below
{ClassName}.cls with ApexDoc{ClassName}.cls-meta.xmlGenerate test classes -- Load the skill platform-apex-test-generate to create {ClassName}Test.cls and {ClassName}Test.cls-meta.xml. Apex tests are required to deploy; never create or edit test files without loading it.
Steps 6 and 7 each require a tool invocation and produce output that must appear in the Step 8 report. Do not present the report until both have run and their output is captured.
Run code analyzer
dx-code-analyzer-run skill on all generated/updated .cls files.sev0, sev1, and sev2 violations; re-run until clean.sf code-analyzer run --target <target>. If both are unavailable, record code_analyzer=unavailable: <error> in the report.Execute Apex tests
{ClassName}Test via sf apex run test.platform-apex-test-generate; iterate until the tests pass.test_execution=unavailable: <error> in the report.Analyzer line must contain the actual Step 6 tool output (or code_analyzer=unavailable: <reason> after attempting it).Testing line must contain the actual Step 7 results (or test_execution=unavailable: <reason> after attempting it).If any constraint would be violated in generated code, stop and explain the problem before proceeding:
| Constraint | Rationale |
|---|---|
| Place all SOQL outside loops | Avoid query governor limits (100 queries) |
| Place all DML outside loops | Avoid DML governor limits (150 statements) |
| Declare a sharing keyword on every class | Prevent unintended without sharing defaults and data exposure |
| Use Custom Metadata/Labels/describe calls instead of hardcoded IDs | Ensure portability across orgs |
| Always handle exceptions (log, rethrow, or recover) | Prevent silent failures |
| Use bind variables for all dynamic SOQL with user input | Prevent SOQL injection |
Use Apex-native collections (List, Map, Set) rather than Java types | Prevent compile errors |
| Verify methods exist in Apex before use | Prevent reliance on non-existent APIs |
Avoid System.debug() in main code paths | Debug statements evaluate even when loggign is not active and consume CPU. Use a logging framework if required on main code paths |
Never use @future methods | Use Queueable with System.Finalizer; @future cannot chain, cannot be called from Batch, and cannot accept non-primitive types |
Database.update(records, false)) and process SaveResult for errorsMap<Id, SObject> constructor for efficient ID-based lookups from query resultsMap<Id, List<SObject>> to group child records by parent; build the map in a single loop before processingSet<Id> for deduplication and membership checks; prefer Set.contains() over List.contains()AggregateResult with GROUP BY for rollup calculations instead of querying and counting in ApexTrigger.oldMap or prior state before adding to the update listLimits.getQueries(), Limits.getDmlStatements(), Limits.getCpuTime() to monitor consumption in complex transactionsWHERE clauses; use indexed fields (Id, Name, OwnerId, lookup/master-detail fields, ExternalId fields, custom indexes) in filters when possibleSELECT * does not exist in SOQL -- always specify the exact fields neededLIMIT clauses to bound result sets; use ORDER BY for deterministic results__mdt), do NOT use SOQL — use the built-in methods ({CustomMdt__mdt}.getAll().values(), getInstance(), etc.)without sharing keyword classes with API versions 67.0 and up will throw when the running user does not have the proper field or object-level security. If API versions are being updated, ensure queries are safeguarded properly, and that tests are updated accordingly. Only explicitly justified usages of SYSTEM_MODE variants within queries should be allowed by default.Cache.Org / Cache.Session) for frequently accessed, rarely changed data; set a TTL and always handle cache misses — cache can be evicted at any timeprivate static Map fields as transaction-scoped caches to prevent duplicate queries within the same execution context; lazy-initialize on first accesswith sharing; document justification for without sharing or inherited sharingWITH USER_MODE in SOQL and AccessLevel.USER_MODE for Database DML for CRUD/FLS enforcement — these are the defaults for all Apex classes with API versions of 67.0 or higherSchema.describeAuraHandledException for @AuraEnabled user-facing errors (no internal details)without sharing requires a Custom Permission checkwithout sharing logic in dedicated helper classes; call from with sharing entry points to limit elevated-access scopeBefore finalizing, verify: CRUD/FLS enforced (SOQL + DML) · explicit sharing keyword on every class · no hardcoded secrets or Record IDs · PII excluded from logs and error messages · error messages sanitized for end users.
Exception; include context in messagestry/catch only around code that can throw (DML, callouts, JSON parsing, casts); avoid defensive wrapping of simple assignments/collection ops/arithmeticnew CustomException('message', cause) (do not replace stack trace with concatenated messages)@AuraEnabled methods, catch exceptions and rethrow as AuraHandledExceptionException and either rethrow it or wrap it in a minimal custom exception that preserves the original cause.return early in private/trigger-handler methods, throw exceptions in public APIs, record.addError() in validation servicesnull?.) for chained property accessmap.get(key) inline unless presence is guaranteed; use containsKey, assignment + null check, or safe navigation first??) for default valuesString.isBlank(value) over manual checks like value == null || value.trim().isEmpty()UPPER_SNAKE_CASEprivate static final constants or a constants classLabel. custom labels for user-facing strings'); use literal single quotes ' in Apex string literals| Type | Pattern | Example |
|---|---|---|
| Service | {SObject}Service | AccountService |
| Selector | {SObject}Selector | AccountSelector |
| Domain | {SObject}Domain | OpportunityDomain |
| Batch | {Descriptive}Batch | AccountDeduplicationBatch |
| Queueable | {Descriptive}Queueable | ExternalSyncQueueable |
| Schedulable | {Descriptive}Schedulable | DailyCleanupSchedulable |
| DTO | {Descriptive}DTO | AccountMergeRequestDTO |
| Wrapper | {Descriptive}Wrapper | OpportunityLineWrapper |
| Utility | {Descriptive}Util | StringUtil |
| Interface | I{Descriptive} | INotificationService |
| Abstract | Abstract{Descriptive} | AbstractIntegrationService |
| Exception | {Descriptive}Exception | AccountServiceException |
| REST Resource | {SObject}RestResource | AccountRestResource |
| Trigger | {SObject}Trigger | AccountTrigger |
| Trigger Action | TA_{SObject}_{Action} | TA_Account_SetDefaults |
Additional naming rules:
PascalCasecamelCase, start with a verb (get, create, process, validate, is, has, can)camelCase, descriptive nouns; Lists as plural nouns (e.g., accounts, relatedContacts); Maps as {value}By{key} (e.g., accountsById); Sets as {noun}IdsUPPER_SNAKE_CASEacc, tks, rec)public/global method@param, @return, @throws, @example where helpfulClass-level format:
/**
* Provides services for geolocation and address conversion.
*/
public with sharing class GeolocationService { }
Method-level format:
/**
* @param paramName Description of the parameter
* @return Description of the return value
* @example
* List<Account> results = AccountService.deduplicateAccounts(accountIds);
*/
| Layer | Owns | Must NOT contain |
|---|---|---|
| Trigger | Event routing only | Business logic, orchestration |
| Handler/Service | Flow control, coordination | Inline SOQL/DML/HTTP/parsing |
| Domain | Business rules, validation | Queries, callouts, persistence details |
| Data/Integration | SOQL, DML, HTTP | Business decisions |
| Scenario | Default | Key Traits |
|---|---|---|
| Standard async work | Queueable | Job ID, chaining, non-primitive types, configurable delay (up to 10 min via AsyncOptions), dedup signatures |
| Very large datasets | Batch Apex | Chunked processing, max 5 concurrent; use QueryLocator for large scopes |
| Modern batch alternative | CursorStep (Database.Cursor) | 2000-record chunks, higher throughput, no 5-job limit |
| Recurring schedule | Scheduled Flow (preferred) or Schedulable | Schedulable has 100-job limit; use only when chaining to Batch or needing complex Apex logic |
| Post-job cleanup | Finalizer (System.Finalizer) | Runs regardless of Queueable success/failure |
| Long-running callouts | Continuation | Up to 3 per transaction, 3 parallel |
| Delays > 10 minutes | System.scheduleBatch() | Schedule a Batch job at a specific future time |
| Legacy fire-and-forget | @future | Do not use in new code — see Hard-Stop Constraints; replace with Queueable + Finalizer |
assets/service.cls · Reference: references/AccountService.clswith sharing; stateless — no public fields or mutable instance state; keep public APIs focused and static where reasonableAccountServiceException)assets/selector.cls · Reference: references/AccountSelector.clsinherited sharing; one per SObject or query domainList<SObject> or Map<Id, SObject>; use a shared base field list constant (no inline duplication)WITH USER_MODEassets/domain.clswith sharing; encapsulate field defaults, derivations, and validationsassets/batch.cls · Reference: references/AccountDeduplicationBatch.clswith sharing; implement Database.Batchable<SObject> (add Database.Stateful when tracking across chunks)start() = query definition; execute() = business logic; finish() = logging/notificationQueryLocator for large datasets; handle partial failures via Database.SaveResultassets/queueable.clswith sharing; implement Queueable and optionally Database.AllowsCallouts when HTTP callouts are neededFinalizer for recovery/cleanupAsyncOptions for configurable delay (up to 10 min) and dedup signaturesassets/schedulable.clswith sharing; execute() delegates to Queueable or BatchscheduleDaily() helperassets/dto.clsComparable when ordering matters@JsonAccess on private/protected inner DTOs that are serialized/deserializedassets/utility.clspublic static; private constructorassets/interface.clsassets/abstract.clswith sharing; offer default behavior via virtual methodsprotected virtual or protected abstractassets/exception.clsException with descriptive names(), ('msg'), (cause), ('msg', cause)assets/trigger.clsnew MetadataTriggerHandler().run();TriggerAction.{Context}Trigger_Action__mdt (actions are inactive without registration)TA_{SObject}_{ActionName}; prefer field-value comparison over static booleans for recursion@InvocableMethod)assets/invocable.clswith sharing; inner Request/Response with @InvocableVariablepublic static; non-static or single-object signatures will not compileList<Request>, return List<Response>; bulkify (SOQL/DML outside loops)label (required — Flow Builder display name), description, category (groups actions in Builder), callout=true (required when method makes HTTP callouts)@InvocableVariable parameters: label (required), description, required=true/false@InvocableVariable supports: primitives, Id, SObject, List<T> only (no Map/Set/Blob); use List<Id> or List<SObject> fields for Flow collection I/OisSuccess, errorMessage, and errorType (e.getTypeName()) in Response@RestResource)assets/rest-resource.clsglobal with sharing; both class and methods must be global@RestResource(urlMapping='/{resource}/v1/*')200/201/400/404/422/500); never default all errors to 500Pattern.matches('[a-zA-Z0-9]{15,18}', value)); bind all user input in SOQLLIMIT/ORDER BY in queries; implement pagination (pageSize/offset)ApiResponse wrapper (success, message, data/records); inner request/response DTOs@AuraEnabled Controllerwith sharing; use WITH USER_MODE in all SOQL@AuraEnabled(cacheable=true) only for read-only queries; leave cacheable unset for DML operationsAuraHandledException with user-friendly messagesDeliverables per class:
{ClassName}.cls{ClassName}.cls-meta.xml (default API version 66.0 or higher unless specified){ClassName}Test.cls (generated via platform-apex-test-generate skill){ClassName}Test.cls-meta.xml (generated via platform-apex-test-generate skill)Deliverables per trigger:
{TriggerName}.trigger{TriggerName}.trigger-meta.xml (default API version 66.0 or higher unless specified)Meta XML template:
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>{API_VERSION}</apiVersion>
<status>Active</status>
</ApexClass>
Report in this order:
Apex work: <summary>
Files: <paths>
Design: <pattern / framework choices>
Workflow: all steps completed (1-8); any N/A justified
Risks: <security, bulkification, async, dependency notes>
Analyzer: <REQUIRED -- paste actual code analyzer output or state "code_analyzer=unavailable: <reason>">
Testing: <REQUIRED -- paste actual test execution results (pass/fail, coverage) or state "test_execution=unavailable: <reason>">
Deploy: <dry-run or next step>
| Need | Delegate to |
|---|---|
| Apex tests / fix failures | platform-apex-test-generate skill |
| Describe objects/fields | metadata skill (if available) |
| Deploy to org | deploy skill (if available) |
| Flow calling Apex | Flow skill (if available) |
| LWC calling Apex | LWC skill (if available) |
This skill handles production .cls/.trigger/.apex issues only: compile/parse failures, deployment dependency errors, runtime governor-limit failures. For test execution, assertions, coverage, or sf apex run test failures, delegate to platform-apex-test-generate.
assets/abstract.cls (opens in a new tab)assets/batch.cls (opens in a new tab)assets/domain.cls (opens in a new tab)assets/dto.cls (opens in a new tab)assets/exception.cls (opens in a new tab)assets/interface.cls (opens in a new tab)assets/invocable.cls (opens in a new tab)assets/queueable.cls (opens in a new tab)assets/rest-resource.cls (opens in a new tab)assets/schedulable.cls (opens in a new tab)assets/selector.cls (opens in a new tab)assets/service.cls (opens in a new tab)assets/trigger.cls (opens in a new tab)assets/utility.cls (opens in a new tab)references/AccountDeduplicationBatch.cls (opens in a new tab)references/AccountSelector.cls (opens in a new tab)references/AccountService.cls (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
apex, salesforce, class-generation, code-review, trigger-design
21 skills in this plugin
/agentforce-architecture-analyzeDeclared architecture snapshot for one Agentforce agent: planner, topics, actions, flows, Apex, prompt templates, and NGA plugins. Renders a human-readable architecture document and Mermaid invocation graph from design-time metadata (not runtime audit rows). TRIGGER when user asks to describe, diagram, inventory, audit, document, or diff (e.g. v3 vs v5) the architecture / action tree / topic structure / tool inventory of a specific agent by agent API name in a specific org. DO NOT TRIGGER for runtime session traces, conversation transcripts, generation timings, or gateway audit chains — this skill reads design-time metadata only (use agentforce-d360-analyze for session traces)./agentforce-generateBuild, modify, audit, repair, optimize, debug, and deploy agents with Agentforce Agent Script. TRIGGER when: user creates, reviews, or changes .agent files or aiAuthoringBundle metadata; asks to fix AgentScript, audit an existing agent, run an AgentScript health check, common-pitfall review, or baseline-versus-candidate repair loop; changes a response, action, subagent, route, state flow, or Agent Spec; migrates or upgrades a legacy GenAiPlannerBundle Agentforce agent (NOT an Einstein Bot) to an aiAuthoringBundle (Agent Script) agent; previews, debugs, deploys, publishes, or tests agents; uses sf agent generate/preview/publish/test; or manages Agentforce MCP servers, tools, assets, or authentication. DO NOT TRIGGER when: Apex, Flow, Prompt Template, Experience Cloud, or general Salesforce CLI work is unrelated to Agent Script; the source is an Einstein Bot (BotDefinition/BotVersion) — use agentforce-bot-upgrade; or the primary input is a production session or trace ID rather than an agent artifact.npx claudepluginhub reej-consulting/reej-sf-skills --plugin sf-coreOther plugins' skills for the same job