Skip to content

forcedotcom/sf-skills / plugins/builder/salesforce-development/skills/platform-apex-generate

platform-apex-generate

Verified

Primary Apex authoring skill for class generation, refactoring, and review. ALWAYS ACTIVATE when the user mentions Apex, .cls, triggers, or asks to create/refactor a class (service, selector, domain, batch, queueable, schedulable, invocable, DTO, utility, interface, abstract, exception, REST resource). Use this skill for requests involving SObject CRUD, mapping collections, fetching related records, scheduled jobs, batch jobs, trigger design, @AuraEnabled controllers, @RestResource endpoints, custom REST APIs, or code review of existing Apex.

assets/queueable.cls

View on GitHub
/**
 * Queueable Apex class for {describe the async operation}.
 *              Accepts data through the constructor for stateful processing.
 *              Optionally implements Database.AllowsCallouts for external integrations.
 *
 * @example
 * // Enqueue the job
 * Id jobId = System.enqueueJob(new {ClassName}(recordIds));
 */
public with sharing class {ClassName} implements Queueable /*, Database.AllowsCallouts */ {

    // ─── Constants ───────────────────────────────────────────────────────
    private static final Integer MAX_CHAIN_DEPTH = 5;

    // ─── Instance Variables (Stateful) ───────────────────────────────────
    private Set<Id> recordIds;
    private Integer chainDepth;

    // ─── Constructors ────────────────────────────────────────────────────

    /**
     * Creates a new queueable job to process the specified records
     * @param recordIds Set of record Ids to process
     */
    public {ClassName}(Set<Id> recordIds) {
        this(recordIds, 0);
    }

    /**
     * Creates a new queueable job with chain depth tracking
     * @param recordIds Set of record Ids to process
     * @param chainDepth Current depth in the queueable chain
     */
    public {ClassName}(Set<Id> recordIds, Integer chainDepth) {
        this.recordIds = recordIds ?? new Set<Id>();
        this.chainDepth = chainDepth;
    }

    // ─── Queueable Interface ─────────────────────────────────────────────

    /**
     * Executes the asynchronous work
     * @param context The queueable context
     */
    public void execute(QueueableContext context) {
        if (this.recordIds.isEmpty()) {
            return;
        }

        try {
            // TODO: Implement the async processing logic
            // List<{SObject}> records = {SObject}Selector.selectByIds(this.recordIds);
            // ... process records ...

            // Chain to next job if there's more work and we haven't hit the depth limit
            chainIfNeeded();

        } catch (Exception e) {
            handleError(context.getJobId(), e);
        }
    }

    // ─── Private Helpers ─────────────────────────────────────────────────

    /**
     * Chains to the next queueable job if needed, with depth guard
     */
    private void chainIfNeeded() {
        // TODO: Determine if chaining is needed (e.g., remaining records to process)
        Set<Id> remainingIds = new Set<Id>();

        if (!remainingIds.isEmpty() && this.chainDepth < MAX_CHAIN_DEPTH) {
            if (!Test.isRunningTest()) {
                System.enqueueJob(new {ClassName}(remainingIds, this.chainDepth + 1));
            }
        }
    }

    /**
     * Handles errors during execution
     * @param jobId The async job Id
     * @param e The exception that occurred
     */
    private void handleError(Id jobId, Exception e) {
        System.debug(LoggingLevel.ERROR,
            '{ClassName} failed (Job: ' + jobId + '): ' +
            e.getMessage() + '\n' + e.getStackTraceString()
        );
        // TODO: Persist error to a log object or send notification
    }
}
brainstormingobra/superpowersYou MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation).Stars: 322kUpdated Claude CodeCodexVerifiedInstall
brand-guidelinesanthropics/skillsApplies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
frontend-designanthropics/skillsGuidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
mcp-builderanthropics/skillsGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).Stars: 198kUpdated Claude CodeCodexVerifiedInstall