Skip to content

forcedotcom/sf-skills / plugins/builder/salesforce-development/skills/platform-data-manage

platform-data-manage

Verified

Salesforce data operations with 130-point scoring. Use to create, update, delete, bulk import/export, generate test data, and clean up org records via sf CLI and anonymous Apex. TRIGGER on creating test data, bulk import/export, sf data CLI commands, data-factory patterns for Apex tests, or seeding/cleaning org records. DO NOT TRIGGER for SOQL query writing only (use platform-soql-query), Apex test execution (use platform-apex-test-run), or metadata deployment (use platform-metadata-deploy).

FileKindSize
README.mdmarkdown4.5 KB
SKILL.mdskill md10.5 KB
assets/bulk/bulk-insert-10000.apexother12.3 KB
assets/bulk/bulk-insert-200.apexother12.4 KB
assets/bulk/bulk-insert-500.apexother13.1 KB
assets/bulk/bulk-upsert-external-id.apexother13.4 KB
assets/cleanup/delete-by-created-date.apexother15.9 KB
assets/cleanup/delete-by-name.apexother12.9 KB
assets/cleanup/delete-test-data.apexother16.6 KB
assets/cleanup/rollback-transaction.apexother12.4 KB
assets/csv/account-import.csvother1.8 KB
assets/csv/contact-import.csvother1.9 KB
assets/csv/custom-object-import.csvother1.1 KB
assets/csv/opportunity-import.csvother1.6 KB
assets/factories/account-factory.apexother5.6 KB
assets/factories/case-factory.apexother8.1 KB
assets/factories/contact-factory.apexother5.9 KB
assets/factories/custom-object-factory.apexother10.8 KB
assets/factories/event-factory.apexother9.6 KB
assets/factories/hierarchy-factory.apexother16.0 KB
assets/factories/lead-factory.apexother6.4 KB
assets/factories/opportunity-factory.apexother7.3 KB
assets/factories/task-factory.apexother8.1 KB
assets/factories/user-factory.apexother8.8 KB
assets/json/account-contact-tree.jsonconfig3.6 KB
assets/json/account-opportunity-tree.jsonconfig3.3 KB
assets/json/full-hierarchy-tree.jsonconfig5.8 KB
assets/soql/aggregate.soqlother12.3 KB
assets/soql/child-to-parent.soqlother9.8 KB
assets/soql/parent-to-child.soqlother8.6 KB
assets/soql/polymorphic.soqlother11.1 KB
assets/soql/subquery.soqlother16.2 KB
references/anonymous-apex-guide.mdmarkdown2.0 KB
references/bulk-operations-guide.mdmarkdown1.8 KB
references/bulk-testing-example.mdmarkdown4.9 KB
references/cleanup-rollback-example.mdmarkdown8.2 KB
references/cleanup-rollback-guide.mdmarkdown1.7 KB
references/crud-workflow-example.mdmarkdown4.0 KB
references/governor-limits-reference.mdmarkdown1.8 KB
references/orchestration.mdmarkdown7.0 KB
references/relationship-query-examples.mdmarkdown5.7 KB
references/sf-cli-data-commands.mdmarkdown2.8 KB
references/soql-relationship-guide.mdmarkdown2.0 KB
references/test-data-best-practices.mdmarkdown3.2 KB
references/test-data-factory-usage.mdmarkdown7.6 KB
references/test-data-patterns.mdmarkdown2.4 KB
scripts/soql_validator.pyscript10.9 KB
scripts/validate_data_operation.pyscript13.5 KB

assets/factories/custom-object-factory.apex

View on GitHub
/**
 * Test Data Factory Template for Custom Objects
 *
 * INSTRUCTIONS:
 * 1. Copy this file and rename to TestDataFactory_[YourObject].cls
 * 2. Replace {{ObjectName}} with your object API name (e.g., Invoice__c)
 * 3. Replace {{ObjectLabel}} with display name (e.g., Invoice)
 * 4. Update buildRecord() with your object's fields
 * 5. Add object-specific creation methods as needed
 *
 * Usage:
 *   List<{{ObjectName}}> records = TestDataFactory_{{ObjectLabel}}.create(200);
 *   List<{{ObjectName}}> recordsNoInsert = TestDataFactory_{{ObjectLabel}}.create(200, false);
 */
public class TestDataFactory_{{ObjectLabel}} {

    // ═══════════════════════════════════════════════════════════════════════
    // CONFIGURATION - Update these for your object
    // ═══════════════════════════════════════════════════════════════════════

    private static final String DEFAULT_NAME_PREFIX = 'Test {{ObjectLabel}} ';

    // Add default values for required picklist fields
    // private static final String DEFAULT_STATUS = 'Draft';
    // private static final String DEFAULT_TYPE = 'Standard';

    // ═══════════════════════════════════════════════════════════════════════
    // STANDARD FACTORY METHODS
    // ═══════════════════════════════════════════════════════════════════════

    /**
     * Create and insert records with default values
     * @param count Number of records to create
     * @return List of inserted records with IDs
     */
    public static List<{{ObjectName}}> create(Integer count) {
        return create(count, true);
    }

    /**
     * Create records with insert option
     * @param count Number of records to create
     * @param doInsert Whether to insert records
     * @return List of records
     */
    public static List<{{ObjectName}}> create(Integer count, Boolean doInsert) {
        List<{{ObjectName}}> records = new List<{{ObjectName}}>();
        for (Integer i = 0; i < count; i++) {
            records.add(buildRecord(i));
        }
        if (doInsert && !records.isEmpty()) {
            insert records;
        }
        return records;
    }

    // ═══════════════════════════════════════════════════════════════════════
    // RELATIONSHIP METHODS - Uncomment and modify if object has lookups
    // ═══════════════════════════════════════════════════════════════════════

    /**
     * Create records for a specific parent Account
     * Uncomment if your object has an Account lookup
     */
    /*
    public static List<{{ObjectName}}> createForAccount(Integer count, Id accountId) {
        return createForAccount(count, accountId, true);
    }

    public static List<{{ObjectName}}> createForAccount(Integer count, Id accountId, Boolean doInsert) {
        List<{{ObjectName}}> records = new List<{{ObjectName}}>();
        for (Integer i = 0; i < count; i++) {
            {{ObjectName}} record = buildRecord(i);
            record.Account__c = accountId;  // Update with your lookup field API name
            records.add(record);
        }
        if (doInsert && !records.isEmpty()) {
            insert records;
        }
        return records;
    }
    */

    /**
     * Create records for a specific parent (generic lookup)
     * Uncomment and modify for your parent object
     */
    /*
    public static List<{{ObjectName}}> createForParent(Integer count, Id parentId) {
        List<{{ObjectName}}> records = new List<{{ObjectName}}>();
        for (Integer i = 0; i < count; i++) {
            {{ObjectName}} record = buildRecord(i);
            record.Parent__c = parentId;  // Update with your lookup field API name
            records.add(record);
        }
        if (!records.isEmpty()) {
            insert records;
        }
        return records;
    }
    */

    // ═══════════════════════════════════════════════════════════════════════
    // VARIATION METHODS - Add methods for specific field variations
    // ═══════════════════════════════════════════════════════════════════════

    /**
     * Create records with a specific Status
     * Uncomment if your object has a Status picklist
     */
    /*
    public static List<{{ObjectName}}> createWithStatus(Integer count, String status) {
        List<{{ObjectName}}> records = new List<{{ObjectName}}>();
        for (Integer i = 0; i < count; i++) {
            {{ObjectName}} record = buildRecord(i);
            record.Status__c = status;  // Update with your status field API name
            records.add(record);
        }
        if (!records.isEmpty()) {
            insert records;
        }
        return records;
    }
    */

    /**
     * Create records with varied values for comprehensive testing
     * Modify for your object's key picklist fields
     */
    /*
    public static List<{{ObjectName}}> createWithVariedValues(Integer count) {
        List<String> statuses = new List<String>{'Draft', 'Active', 'Complete', 'Cancelled'};

        List<{{ObjectName}}> records = new List<{{ObjectName}}>();
        for (Integer i = 0; i < count; i++) {
            {{ObjectName}} record = buildRecord(i);
            record.Status__c = statuses[Math.mod(i, statuses.size())];
            records.add(record);
        }

        if (!records.isEmpty()) {
            insert records;
        }
        return records;
    }
    */

    // ═══════════════════════════════════════════════════════════════════════
    // RECORD BUILDER - Customize for your object's fields
    // ═══════════════════════════════════════════════════════════════════════

    /**
     * Build a single record with default values
     *
     * UPDATE THIS METHOD with your object's fields:
     * 1. Add all required fields
     * 2. Add fields needed for testing
     * 3. Use realistic test values
     *
     * @param index Record index for unique naming
     * @return Record (not inserted)
     */
    private static {{ObjectName}} buildRecord(Integer index) {
        String indexStr = String.valueOf(index).leftPad(5, '0');

        return new {{ObjectName}}(
            Name = DEFAULT_NAME_PREFIX + indexStr

            // ─────────────────────────────────────────────────────────────
            // ADD YOUR FIELDS BELOW
            // ─────────────────────────────────────────────────────────────

            // Text fields
            // , Description__c = 'Test {{ObjectLabel}} created by TestDataFactory'

            // Picklist fields (use valid picklist values)
            // , Status__c = DEFAULT_STATUS
            // , Type__c = DEFAULT_TYPE

            // Number fields
            // , Amount__c = 1000 + (index * 100)
            // , Quantity__c = 1 + index

            // Date fields
            // , StartDate__c = Date.today()
            // , EndDate__c = Date.today().addDays(30 + index)

            // DateTime fields
            // , ScheduledDateTime__c = DateTime.now().addDays(index)

            // Checkbox fields
            // , IsActive__c = true

            // Currency fields
            // , TotalAmount__c = 10000.00 + (index * 500)

            // Percent fields
            // , DiscountPercent__c = 10 + index

            // Email fields
            // , ContactEmail__c = 'test' + index + '@testfactory.example.com'

            // Phone fields
            // , ContactPhone__c = '(555) 900-' + String.valueOf(1000 + index)

            // URL fields
            // , Website__c = 'https://test' + index + '.example.com'

            // Lookup fields (requires parent record ID)
            // , Account__c = accountId
            // , Contact__c = contactId

            // ─────────────────────────────────────────────────────────────
        );
    }

    // ═══════════════════════════════════════════════════════════════════════
    // UTILITY METHODS
    // ═══════════════════════════════════════════════════════════════════════

    /**
     * Get IDs of created records for cleanup
     * @param records List of records
     * @return Set of record IDs
     */
    public static Set<Id> getIds(List<{{ObjectName}}> records) {
        Set<Id> ids = new Set<Id>();
        for ({{ObjectName}} record : records) {
            if (record.Id != null) {
                ids.add(record.Id);
            }
        }
        return ids;
    }

    /**
     * Delete records by IDs (cleanup utility)
     * @param recordIds Set of record IDs to delete
     */
    public static void cleanup(Set<Id> recordIds) {
        if (!recordIds.isEmpty()) {
            delete [SELECT Id FROM {{ObjectName}} WHERE Id IN :recordIds];
        }
    }

    /**
     * Delete records by Name pattern (cleanup utility)
     * @param namePattern LIKE pattern (e.g., 'Test%')
     */
    public static void cleanupByName(String namePattern) {
        List<{{ObjectName}}> records = [
            SELECT Id FROM {{ObjectName}}
            WHERE Name LIKE :namePattern
            LIMIT 10000
        ];
        if (!records.isEmpty()) {
            delete records;
        }
    }
}
finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the workStars: 322kUpdated Claude CodeCodexVerifiedInstall
systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixesStars: 322kUpdated Claude CodeCodexVerifiedInstall
test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation codeStars: 322kUpdated Claude CodeCodexVerifiedInstall
skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy.Stars: 198kUpdated Claude CodeCodexVerifiedInstall