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/bulk/bulk-insert-500.apex

View on GitHub
/**
 * ═══════════════════════════════════════════════════════════════════════════════
 * BULK INSERT 500+ RECORDS
 * For testing batch Apex and queueable job bulkification
 * ═══════════════════════════════════════════════════════════════════════════════
 *
 * PURPOSE:
 * Test that batch Apex classes and queueable jobs handle larger datasets.
 * Default batch size is 200, so 500+ tests multiple batch iterations.
 *
 * WHY 500 RECORDS:
 * • Tests 2-3 batch iterations (200 records per batch)
 * • Validates stateful processing across batches
 * • Ensures aggregate operations work correctly
 *
 * BATCH APEX CONTEXT:
 * • Default scope is 200 records per execute()
 * • Maximum scope is 2000 records per execute()
 * • 50 million records can be processed total
 *
 * ═══════════════════════════════════════════════════════════════════════════════
 */

// ═══════════════════════════════════════════════════════════════════════════════
// CONFIGURATION
// ═══════════════════════════════════════════════════════════════════════════════

Integer accountCount = 100;     // 100 accounts
Integer contactsPerAccount = 3; // 300 contacts total
Integer oppsPerAccount = 2;     // 200 opportunities total
// Total: ~600 records

String namePrefix = 'BatchTest';
DateTime testStartTime = DateTime.now();

// ═══════════════════════════════════════════════════════════════════════════════
// TRACKING COLLECTIONS
// ═══════════════════════════════════════════════════════════════════════════════

Map<String, Set<Id>> createdRecords = new Map<String, Set<Id>>{
    'Account' => new Set<Id>(),
    'Contact' => new Set<Id>(),
    'Opportunity' => new Set<Id>()
};

// ═══════════════════════════════════════════════════════════════════════════════
// LIMIT TRACKING
// ═══════════════════════════════════════════════════════════════════════════════

Integer startQueries = Limits.getQueries();
Integer startDml = Limits.getDmlStatements();
Integer startDmlRows = Limits.getDmlRows();
Integer startCpu = Limits.getCpuTime();

System.debug('═══════════════════════════════════════════════════════════════');
System.debug('Starting Batch-Size Test: ' + accountCount + ' accounts');
System.debug('Expected total records: ~' + (accountCount + accountCount * contactsPerAccount + accountCount * oppsPerAccount));
System.debug('═══════════════════════════════════════════════════════════════');

// ═══════════════════════════════════════════════════════════════════════════════
// STEP 1: CREATE ACCOUNTS IN CHUNKS
// ═══════════════════════════════════════════════════════════════════════════════

List<Account> accounts = new List<Account>();
List<String> industries = new List<String>{
    'Technology', 'Healthcare', 'Finance', 'Manufacturing',
    'Retail', 'Education', 'Energy', 'Media', 'Government', 'Nonprofit'
};
List<String> types = new List<String>{'Prospect', 'Customer', 'Partner'};

for (Integer i = 0; i < accountCount; i++) {
    accounts.add(new Account(
        Name = namePrefix + '_Account_' + String.valueOf(i).leftPad(5, '0'),
        Industry = industries[Math.mod(i, industries.size())],
        Type = types[Math.mod(i, types.size())],
        AnnualRevenue = 100000 + (i * 25000),
        NumberOfEmployees = 25 + (i * 10),
        BillingCity = 'San Francisco',
        BillingState = 'CA',
        BillingCountry = 'USA',
        Description = 'Batch test account created at ' + testStartTime
    ));
}

insert accounts;
for (Account acc : accounts) {
    createdRecords.get('Account').add(acc.Id);
}
System.debug('✓ Created ' + accounts.size() + ' Accounts');

// ═══════════════════════════════════════════════════════════════════════════════
// STEP 2: CREATE CONTACTS IN CHUNKS (to stay under DML row limit)
// ═══════════════════════════════════════════════════════════════════════════════

List<Contact> allContacts = new List<Contact>();
Integer contactIndex = 0;
List<String> titles = new List<String>{
    'CEO', 'CFO', 'CTO', 'VP Sales', 'VP Marketing',
    'Director', 'Manager', 'Analyst', 'Developer', 'Consultant'
};

for (Account acc : accounts) {
    for (Integer i = 0; i < contactsPerAccount; i++) {
        String idx = String.valueOf(contactIndex++).leftPad(5, '0');
        allContacts.add(new Contact(
            FirstName = namePrefix,
            LastName = 'Contact_' + idx,
            AccountId = acc.Id,
            Email = namePrefix.toLowerCase() + '.contact' + idx + '@batchtest.example.com',
            Phone = '(555) 200-' + String.valueOf(1000 + Math.mod(contactIndex, 9000)),
            Title = titles[Math.mod(contactIndex, titles.size())],
            Department = 'Department ' + Math.mod(contactIndex, 5),
            MailingCity = 'San Francisco',
            MailingState = 'CA'
        ));
    }
}

// Insert contacts
insert allContacts;
for (Contact con : allContacts) {
    createdRecords.get('Contact').add(con.Id);
}
System.debug('✓ Created ' + allContacts.size() + ' Contacts');

// ═══════════════════════════════════════════════════════════════════════════════
// STEP 3: CREATE OPPORTUNITIES
// ═══════════════════════════════════════════════════════════════════════════════

List<Opportunity> allOpportunities = new List<Opportunity>();
Integer oppIndex = 0;
List<String> stages = new List<String>{
    'Prospecting', 'Qualification', 'Needs Analysis',
    'Value Proposition', 'Proposal/Price Quote', 'Negotiation/Review'
};
List<String> leadSources = new List<String>{
    'Web', 'Phone Inquiry', 'Partner Referral', 'Trade Show', 'Other'
};

for (Account acc : accounts) {
    for (Integer i = 0; i < oppsPerAccount; i++) {
        String idx = String.valueOf(oppIndex++).leftPad(5, '0');
        allOpportunities.add(new Opportunity(
            Name = namePrefix + '_Opportunity_' + idx,
            AccountId = acc.Id,
            StageName = stages[Math.mod(oppIndex, stages.size())],
            CloseDate = Date.today().addDays(15 + Math.mod(oppIndex, 90)),
            Amount = 5000 + (oppIndex * 500),
            Probability = 10 + Math.mod(oppIndex, 80),
            Type = 'New Customer',
            LeadSource = leadSources[Math.mod(oppIndex, leadSources.size())]
        ));
    }
}

insert allOpportunities;
for (Opportunity opp : allOpportunities) {
    createdRecords.get('Opportunity').add(opp.Id);
}
System.debug('✓ Created ' + allOpportunities.size() + ' Opportunities');

// ═══════════════════════════════════════════════════════════════════════════════
// REPORT RESULTS
// ═══════════════════════════════════════════════════════════════════════════════

Integer endQueries = Limits.getQueries();
Integer endDml = Limits.getDmlStatements();
Integer endDmlRows = Limits.getDmlRows();
Integer endCpu = Limits.getCpuTime();

Integer totalRecords = createdRecords.get('Account').size() +
                       createdRecords.get('Contact').size() +
                       createdRecords.get('Opportunity').size();

System.debug('');
System.debug('═══════════════════════════════════════════════════════════════');
System.debug('BATCH-SIZE TEST COMPLETE');
System.debug('═══════════════════════════════════════════════════════════════');
System.debug('');
System.debug('📊 RECORDS CREATED:');
System.debug('   Accounts:      ' + createdRecords.get('Account').size());
System.debug('   Contacts:      ' + createdRecords.get('Contact').size());
System.debug('   Opportunities: ' + createdRecords.get('Opportunity').size());
System.debug('   ────────────────────────────────');
System.debug('   TOTAL:         ' + totalRecords);
System.debug('');
System.debug('📈 GOVERNOR LIMITS USED:');
System.debug('   SOQL Queries:     ' + (endQueries - startQueries) + ' / 100 (' + ((endQueries - startQueries) * 100 / 100) + '%)');
System.debug('   DML Statements:   ' + (endDml - startDml) + ' / 150 (' + ((endDml - startDml) * 100 / 150) + '%)');
System.debug('   DML Rows:         ' + endDmlRows + ' / 10000 (' + (endDmlRows * 100 / 10000) + '%)');
System.debug('   CPU Time (ms):    ' + (endCpu - startCpu) + ' / 10000 (' + ((endCpu - startCpu) * 100 / 10000) + '%)');
System.debug('');
System.debug('🔄 BATCH RECOMMENDATIONS:');
System.debug('   Records can be processed in batches of 200 (default)');
System.debug('   This dataset would require ' + Math.ceil((Decimal)totalRecords / 200) + ' batch iterations');
System.debug('');
System.debug('═══════════════════════════════════════════════════════════════');

// ═══════════════════════════════════════════════════════════════════════════════
// CLEANUP SCRIPT
// ═══════════════════════════════════════════════════════════════════════════════
/*
CLEANUP - Run this after testing:

DELETE [SELECT Id FROM Opportunity WHERE Name LIKE 'BatchTest%'];
DELETE [SELECT Id FROM Contact WHERE LastName LIKE 'Contact_%' AND Email LIKE '%batchtest.example.com'];
DELETE [SELECT Id FROM Account WHERE Name LIKE 'BatchTest%'];

System.debug('Cleanup complete');
*/

// ═══════════════════════════════════════════════════════════════════════════════
// OUTPUT FOR CLEANUP VIA SF CLI
// ═══════════════════════════════════════════════════════════════════════════════

System.debug('');
System.debug('CLI Cleanup Commands:');
System.debug('sf data query --query "SELECT Id FROM Account WHERE Name LIKE \'BatchTest%\'" --target-org [alias] --result-format csv > cleanup-accounts.csv');
System.debug('sf data delete bulk --file cleanup-accounts.csv --sobject Account --target-org [alias] --wait 10');
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