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

View on GitHub
/**
 * Domain class for {SObject}.
 *              Encapsulates field-level defaults, derivations, and validations.
 *              Operates only on in-memory SObject data — no SOQL or DML.
 */
public with sharing class {SObject}Domain {

    // ─── Constants ───────────────────────────────────────────────────────
    // TODO: Add constants for default values, statuses, etc.

    // ─── Field Defaults ──────────────────────────────────────────────────

    /**
     * Applies default field values to new {SObject} records.
     *              Call this before insert to ensure consistent defaults.
     * @param records List of {SObject} records to apply defaults to
     */
    public static void applyDefaults(List<{SObject}> records) {
        if (records == null || records.isEmpty()) {
            return;
        }

        for ({SObject} record : records) {
            // TODO: Set default field values
            // Example:
            // if (record.Status__c == null) {
            //     record.Status__c = DEFAULT_STATUS;
            // }
        }
    }

    // ─── Derivations ────────────────────────────────────────────────────

    /**
     * Derives calculated field values based on other fields.
     *              Call this before insert and before update.
     * @param records List of {SObject} records to derive values for
     */
    public static void deriveFields(List<{SObject}> records) {
        if (records == null || records.isEmpty()) {
            return;
        }

        for ({SObject} record : records) {
            // TODO: Derive calculated field values
            // Example:
            // record.FullAddress__c = buildFullAddress(record);
        }
    }

    // ─── Validations ────────────────────────────────────────────────────

    /**
     * Validates {SObject} records and adds errors for any violations.
     *              Call this before insert and before update.
     * @param records List of {SObject} records to validate
     */
    public static void validate(List<{SObject}> records) {
        if (records == null || records.isEmpty()) {
            return;
        }

        for ({SObject} record : records) {
            // TODO: Add validation rules
            // Example:
            // if (String.isBlank(record.Name)) {
            //     record.addError('Name is required.');
            // }
        }
    }

    // ─── Comparisons ────────────────────────────────────────────────────

    /**
     * Determines which fields have changed between old and new record versions.
     *              Useful in before update context.
     * @param oldRecord The previous version of the record
     * @param newRecord The current version of the record
     * @return Set of field API names that have changed
     */
    public static Set<String> getChangedFields({SObject} oldRecord, {SObject} newRecord) {
        Set<String> changedFields = new Set<String>();

        if (oldRecord == null || newRecord == null) {
            return changedFields;
        }

        Map<String, Schema.SObjectField> fieldMap = Schema.SObjectType.{SObject}.fields.getMap();
        for (String fieldName : fieldMap.keySet()) {
            if (oldRecord.get(fieldName) != newRecord.get(fieldName)) {
                changedFields.add(fieldName);
            }
        }

        return changedFields;
    }

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

    // TODO: Add private helper methods as needed
}
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