Newer Version Available
SandboxPostCopy Interface
Namespace
Usage
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.
SandboxPostCopy Methods
The following method is for SandboxPostCopy.
runApexClass(context)
Signature
public void runApexClass(System.SandboxContext context)
Parameters
- context
- Type: System.SandboxContext
- The org ID, sandbox ID, and sandbox name for your sandbox. To work with these values, reference context.organizationId(), context.sandboxId(), and context.sandboxName() in your code.
Return Value
Type: void
SandboxPostCopy Example Implementation
This is an example implementation of the System.SandboxPostCopy interface.
1global class PrepareMySandbox implements SandboxPostCopy {
2 global void runApexClass(SandboxContext context) {
3 System.debug('Org ID: ' + context.organizationId());
4 System.debug('Sandbox ID: ' + context.sandboxId());
5 System.debug('Sandbox Name: ' + context.sandboxName());
6
7 // Insert logic here to prepare the sandbox for use.
8 }
9}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.
1@isTest
2class PrepareMySandboxTest {
3
4 @isTest
5 static void testMySandboxPrep() {
6 // Insert logic here to create records of the objects that the class you’re testing
7 // manipulates.
8
9 Test.startTest();
10
11 Test.testSandboxPostCopyScript(
12 new PrepareMySandbox(), UserInfo.getOrganizationId(),
13 UserInfo.getOrganizationId(), UserInfo.getOrganizationName());
14
15 Test.stopTest();
16
17 // Insert assert statements here to check that the records you created above have
18 // the values you expect.
19 }
20}For more information on testing, see Testing Apex.