SandboxPostCopy Interface

To make your sandbox environment business ready, automate data manipulation or business logic tasks. Extend this interface and add methods to perform post-copy tasks, then specify the class during sandbox creation.

Namespace

System

Usage

Create an Apex class that implements this interface. For example, the following Apex class reports the three contexts available in SandboxPostCopy: your organization ID, sandbox ID, and sandbox name:
global class HelloWorld implements SandboxPostCopy {
  global void runApexClass(SandboxContext context) {
      System.debug('Hello Tester Pester ' + context.organizationId() + ' ' + context.sandboxId() + context.sandboxName());
    }
  }

SandboxPostCopy Methods

The following method is for SandboxPostCopy.

runApexClass(context)

Signature

public void runApexClass(System.SandboxContext context)

Parameters

context
Type: System.SandboxContext
The context for your sandbox.

Return Value

Type: void

SandboxPostCopy Example Implementation

This is an example implementation of the System.SandboxPostCopy interface.

global class HelloWorld implements SandboxPostCopy {
    global void runApexClass(SandboxContext context) {
    System.debug('Hello Tester Pester ' + context.organizationId() + ' 
                  ' + context.sandboxId() + context.sandboxName());
    }
    }

The following example tests the implementation:

    @isTest
    class testHelloWorld{
    @isTest
    static void testSandboxPostCopyScript() {
    HelloWorld apexclass = new HelloWorld();
    Test.testSandboxPostCopyScript(apexClassName, 'orgID', 'sandboxID', 'sandboxName');
    System.assertEquals(1,1,'Test something');