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/abstract.cls

View on GitHub
/**
<<<<<<< Updated upstream
 * @description Abstract base class for {describe the family of classes this serves}.
=======
 * Abstract base class for {describe the family of classes this serves}.
>>>>>>> Stashed changes
 *              Provides common behavior and defines extension points for subclasses.
 *              Subclasses must implement the abstract methods to provide specific behavior.
 *
 * @example
 * // Extending this abstract class:
 * public class SalesforceIntegrationService extends {ClassName} {
 *     protected override String getEndpoint() {
 *         return 'callout:Salesforce_API/services/data/v62.0';
 *     }
 *
 *     protected override Map<String, String> getHeaders() {
 *         return new Map<String, String>{
 *             'Content-Type' => 'application/json'
 *         };
 *     }
 * }
 */
public abstract with sharing class {ClassName} {

    // ─── Constants ───────────────────────────────────────────────────────
    private static final Integer DEFAULT_TIMEOUT_MS = 30000;

    // ─── Protected State ─────────────────────────────────────────────────
    protected Integer timeoutMs;

    // ─── Constructor ─────────────────────────────────────────────────────

    /**
     * Initializes the base class with default configuration
     */
    protected {ClassName}() {
        this.timeoutMs = DEFAULT_TIMEOUT_MS;
    }

    // ─── Abstract Methods (must be implemented by subclasses) ────────────

    /**
     * Returns the endpoint URL for this integration.
     *              Subclasses must provide their specific endpoint.
     * @return The endpoint URL as a String
     */
    protected abstract String getEndpoint();

    /**
     * Returns the HTTP headers for this integration.
     *              Subclasses define their own required headers.
     * @return Map of header name to header value
     */
    protected abstract Map<String, String> getHeaders();

    // ─── Virtual Methods (can be overridden by subclasses) ───────────────

    /**
     * Hook called before the main operation executes.
     *              Override to add pre-processing logic.
     *              Default implementation does nothing.
     * @param context Map of contextual data
     */
    protected virtual void beforeExecute(Map<String, Object> context) {
        // Default: no-op — override in subclass if needed
    }

    /**
     * Hook called after the main operation completes.
     *              Override to add post-processing logic.
     *              Default implementation does nothing.
     * @param context Map of contextual data
     * @param result The result from the operation
     */
    protected virtual void afterExecute(Map<String, Object> context, Object result) {
        // Default: no-op — override in subclass if needed
    }

    // ─── Template Method (common workflow) ───────────────────────────────

    /**
     * Executes the operation using the template method pattern.
     *              Calls beforeExecute → doExecute → afterExecute in sequence.
     * @param context Map of data needed for the operation
     * @return The result of the operation
     */
    public Object execute(Map<String, Object> context) {
        beforeExecute(context);

        Object result;
        try {
            result = doExecute(context);
        } catch (Exception e) {
            handleError(e);
            throw e;
        }

        afterExecute(context, result);
        return result;
    }

    // ─── Protected Helpers ───────────────────────────────────────────────

    /**
     * Core execution logic — override this for the main operation.
     *              Default implementation throws — subclass must provide implementation.
     * @param context Map of data needed for the operation
     * @return The result of the operation
     */
    protected virtual Object doExecute(Map<String, Object> context) {
        throw new UnsupportedOperationException(
            'Subclass must override doExecute()'
        );
    }

    /**
     * Error handler called when doExecute throws.
     *              Override to customize error handling (e.g., logging, retry).
     * @param e The exception that was thrown
     */
    protected virtual void handleError(Exception e) {
        System.debug(LoggingLevel.ERROR,
            this.toString() + ' error: ' + e.getMessage() + '\n' + e.getStackTraceString()
        );
    }

    // ─── Exception ───────────────────────────────────────────────────────

    public class UnsupportedOperationException extends Exception {}
}
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