Create an Apex class that implements this interface. Specify your class during sandbox creation. After your sandbox is created, the runApexClass(context) method in your class runs using the automated process user’s permissions.
The following method is for SandboxPostCopy.
public void runApexClass(System.SandboxContext context)
Type: void
This is an example implementation of the System.SandboxPostCopy interface.
global class PrepareMySandbox implements SandboxPostCopy { global void runApexClass(SandboxContext context) { System.debug('Org ID: ' + context.organizationId()); System.debug('Sandbox ID: ' + context.sandboxId()); System.debug('Sandbox Name: ' + context.sandboxName()); // Insert logic here to prepare the sandbox for use. } }
The following example tests the implementation using the System.Test.testSandboxPostCopyScript() method. This method takes four parameters: a reference to a class that implements the SandboxPostCopy interface, and the three fields on the context object that you pass to the runApexClass(context) method.
@isTest class PrepareMySandboxTest { @isTest static void testMySandboxPrep() { // Insert logic here to create records of the objects that the class you’re testing // manipulates. Test.startTest(); Test.testSandboxPostCopyScript( new PrepareMySandbox(), UserInfo.getOrganizationId(), UserInfo.getOrganizationId(), UserInfo.getOrganizationName()); Test.stopTest(); // Insert assert statements here to check that the records you created above have // the values you expect. } }
For more information on testing, see Testing Apex.