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

View on GitHub
/**
 * Service class for {SObject} business logic.
 *              Follows separation of concerns: delegates queries to {SObject}Selector
 *              and SObject manipulation to {SObject}Domain where applicable.
 */
public with sharing class {SObject}Service {

    // ─── Constants ───────────────────────────────────────────────────────
    private static final String ERROR_NULL_INPUT = 'Input cannot be null or empty.';

    // ─── Public API ──────────────────────────────────────────────────────

    /**
     * {Describe the primary operation}
     * @param recordIds Set of {SObject} Ids to process
     * @return List of processed {SObject} records
     * @throws {SObject}ServiceException if processing fails
     * @example
     * Set<Id> ids = new Set<Id>{ '001xx000003DGbY' };
     * List<{SObject}> results = {SObject}Service.process{SObject}s(ids);
     */
    public static List<{SObject}> process{SObject}s(Set<Id> recordIds) {
        // Guard clause
        if (recordIds == null || recordIds.isEmpty()) {
            throw new {SObject}ServiceException(ERROR_NULL_INPUT);
        }

        // Query via Selector
        List<{SObject}> records = {SObject}Selector.selectByIds(recordIds);

        // Apply business logic
        // TODO: Implement business logic here

        // DML
        try {
            update records;
        } catch (DmlException e) {
            throw new {SObject}ServiceException(
                'Failed to update {SObject} records: ' + e.getMessage()
            );
        }

        return records;
    }

    // ─── Convenience Overloads ───────────────────────────────────────────

    /**
     * Single-record convenience overload
     * @param recordId The {SObject} Id to process
     * @return The processed {SObject} record
     */
    public static {SObject} process{SObject}(Id recordId) {
        List<{SObject}> results = process{SObject}s(new Set<Id>{ recordId });
        return results.isEmpty() ? null : results[0];
    }

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

    // TODO: Add private helper methods as needed

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

    /**
     * Custom exception for {SObject}Service errors
     */
    public class {SObject}ServiceException 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