function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Paul WorltonPaul Worlton 

Why can't a sandbox deploy script create test data?

I have a sandbox deploy script that works fine for setting environment variables but fails to create test data that I always need.  If I run the data insert methods manually, they work fine - but the deploy script seems to skip those methods. Is this an issue with calling static methods or does SandboxPostCopy intentionally block SOQL inserts?

The following is my main function:

// Main deploy script
    global void runApexClass(SandboxContext context) {
        // Set org to dev
        Server__c srv = Server__c.getOrgDefaults();
        srv.Environment__c = 'dev';
        srv.Disable_Rules__c = true;
        upsert srv;
        
        createDummyAccountContact();
        createTestLeads(10);
        createTestLoans(4);
    }
 



 

Raj VakatiRaj Vakati
You need to do it like below 
 
SandboxCreateBulkTestData cls = new SandboxCreateBulkTestData();
        Test.testSandboxPostCopyScript(cls,                  // the instantiated class that implements the SandboxPostCopy interface
                                       UserInfo.getOrganizationId(), // context org ID
                                       UserInfo.getOrganizationId(), // context SandboxID
                                       'sandbox');