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/lead-factory.apex

View on GitHub
/**
 * Test Data Factory for Lead records
 * Supports bulk creation with status and source variations
 *
 * Usage:
 *   List<Lead> leads = TestDataFactory_Lead.create(200);
 *   List<Lead> openLeads = TestDataFactory_Lead.createWithStatus(100, 'Open - Not Contacted');
 *   List<Lead> qualifiedLeads = TestDataFactory_Lead.createQualified(50);
 */
public class TestDataFactory_Lead {

    private static final String DEFAULT_FIRST_NAME_PREFIX = 'Test';
    private static final String DEFAULT_LAST_NAME_PREFIX = 'Lead';
    private static final String DEFAULT_COMPANY_PREFIX = 'Test Company ';
    private static final String DEFAULT_STATUS = 'Open - Not Contacted';
    private static final String DEFAULT_EMAIL_DOMAIN = 'testlead.example.com';

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

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

    /**
     * Create Lead records with a specific Status
     * @param count Number of records to create
     * @param status Lead Status picklist value
     * @return List of inserted Lead records
     */
    public static List<Lead> createWithStatus(Integer count, String status) {
        List<Lead> records = new List<Lead>();
        for (Integer i = 0; i < count; i++) {
            Lead lead = buildRecord(i);
            lead.Status = status;
            records.add(lead);
        }
        if (!records.isEmpty()) {
            insert records;
        }
        return records;
    }

    /**
     * Create qualified Lead records (ready for conversion)
     * @param count Number of records to create
     * @return List of inserted qualified Lead records
     */
    public static List<Lead> createQualified(Integer count) {
        List<Lead> records = new List<Lead>();
        for (Integer i = 0; i < count; i++) {
            Lead lead = buildRecord(i);
            lead.Status = 'Qualified';
            lead.Rating = 'Hot';
            lead.NumberOfEmployees = 100;
            lead.AnnualRevenue = 1000000;
            records.add(lead);
        }
        if (!records.isEmpty()) {
            insert records;
        }
        return records;
    }

    /**
     * Create Leads with varied Lead Sources for attribution testing
     * @param count Number of records to create
     * @return List of inserted Lead records with varied sources
     */
    public static List<Lead> createWithVariedSources(Integer count) {
        List<String> sources = new List<String>{
            'Web', 'Phone Inquiry', 'Partner Referral', 'Purchased List',
            'Other', 'Trade Show', 'Employee Referral', 'External Referral'
        };

        List<Lead> records = new List<Lead>();
        for (Integer i = 0; i < count; i++) {
            Lead lead = buildRecord(i);
            lead.LeadSource = sources[Math.mod(i, sources.size())];
            records.add(lead);
        }

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

    /**
     * Create Leads with varied Industries for segmentation testing
     * @param count Number of records to create
     * @return List of inserted Lead records with varied industries
     */
    public static List<Lead> createWithVariedIndustries(Integer count) {
        List<String> industries = new List<String>{
            'Technology', 'Healthcare', 'Finance', 'Manufacturing',
            'Retail', 'Education', 'Energy', 'Media', 'Government'
        };

        List<Lead> records = new List<Lead>();
        for (Integer i = 0; i < count; i++) {
            Lead lead = buildRecord(i);
            lead.Industry = industries[Math.mod(i, industries.size())];
            records.add(lead);
        }

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

    /**
     * Build a single Lead record with default values
     * @param index Record index for unique naming
     * @return Lead record (not inserted)
     */
    private static Lead buildRecord(Integer index) {
        String indexStr = String.valueOf(index).leftPad(5, '0');
        String firstName = DEFAULT_FIRST_NAME_PREFIX + indexStr;
        String lastName = DEFAULT_LAST_NAME_PREFIX + indexStr;

        return new Lead(
            FirstName = firstName,
            LastName = lastName,
            Company = DEFAULT_COMPANY_PREFIX + indexStr,
            Status = DEFAULT_STATUS,
            Email = firstName.toLowerCase() + '.' + lastName.toLowerCase() + '@' + DEFAULT_EMAIL_DOMAIN,
            Phone = '(555) 400-' + String.valueOf(1000 + index),
            MobilePhone = '(555) 500-' + String.valueOf(1000 + index),
            Title = 'Decision Maker',
            Industry = 'Technology',
            LeadSource = 'Web',
            Rating = 'Warm',
            NumberOfEmployees = 50 + index,
            AnnualRevenue = 500000 + (index * 10000),
            Street = '789 Lead Blvd',
            City = 'San Francisco',
            State = 'CA',
            PostalCode = '94104',
            Country = 'USA',
            Website = 'https://testlead' + index + '.example.com',
            Description = 'Test lead created by TestDataFactory for automated testing'
        );
    }

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

    /**
     * Delete records by IDs (cleanup utility)
     * @param recordIds Set of Lead IDs to delete
     */
    public static void cleanup(Set<Id> recordIds) {
        if (!recordIds.isEmpty()) {
            delete [SELECT Id FROM Lead WHERE Id IN :recordIds];
        }
    }
}
finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the workStars: 323kUpdated Claude CodeCodexVerifiedInstall
systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixesStars: 323kUpdated Claude CodeCodexVerifiedInstall
test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation codeStars: 323kUpdated 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