With the Spring '16 release, there is new functionality where we can set a script to run after refreshing a sandbox. In the documentation it gives an example where it prints the three context variables to a debug log.
Not being sure where that debug log would be stored or how to retrieve it, I created a similar class (api v36.0) that I applied to a developer sandbox (Spring '16, as is prod.):
global class Sandbox_Refresh implements SandboxPostCopy {
global void runApexClass(SandboxContext context) {
insert new Account(name = 'Org Id: ' + context.organizationId() + ' Sandbox Id: ' + context.sandboxId() + ' Sandbox Name: ' + context.sandboxName());
}
}
After creating and also later when refreshing the sandbox, there was no account created, even though running very similar code as anonymous Apex right afterwards worked just fine:
insert new Account(name='test');
I also tried adding a test class, which ran fine in both the sandbox and production. Even when the sandbox post copy code had 100% test coverage, I still wasn't able to see the account created in the sandbox after a refresh.
@isTest
public class Test_Sandbox_Refresh{
public static @isTest void runTest(){
Sandbox_Refresh ClassInstance = new Sandbox_Refresh();
Test.testSandboxPostCopyScript(ClassInstance, UserInfo.getOrganizationId(), '00Dp00000000hjM', 'sandbox2');
}
}
Now I'm not sure why the Sandbox Refresh script didn't work, or where to find a log to trouble-shoot the issue. Has anyone gotten a Sandbox Refresh script to run successfully, and if so, do you have any tips for trouble-shooting when it doesn't work properly?
Test.testSandboxPostCopyScript
to test it? I tried an account insertion with a SandboxPostCopy in a testing context, and it worked. The only other thing I can think of would be to intentionally throw an exception in the runApexClass method and then see where the smoke comes out.