Run Script After Sandbox Creation and Refresh in Salesforce

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.

Create an Apex class that implements SandboxPostCopy and specify the class here.

At sandbox creation, specify a single Apex class to perform the tasks. This class executes every time the sandbox is copied.

Sample code:


  1. global class SandboxPostRefreshHandler implements SandboxPostCopy {   
  2.   
  3.     global void runApexClass( SandboxContext context ) {   
  4.   
  5.         System.debug( context.organizationId() + ' - ' + context.sandboxId() + ' - ' + context.sandboxName() );  
  6.   
  7.     }   
  8.   
  9. }   

Test Class:


  1. @isTest  
  2. private class SandboxPostRefreshHandlerTest {  
  3.   
  4.     @isTest  
  5.     static void testMySandboxPrep() {  
  6.       
  7.         Test.startTest();  
  8.   
  9.         Test.testSandboxPostCopyScript( new SandboxPostRefreshHandler(), UserInfo.getOrganizationId(),  
  10.                                         UserInfo.getOrganizationId(), UserInfo.getOrganizationName() );  
  11.   
  12.         Test.stopTest();  
  13.           
  14.     }  
  15.       
  16. }  


No comments:

Post a Comment