Sandbox Refresh Considerations

After you are set up in production, you may need to refresh or create new sandboxes that copy down data and metadata from production. To make sure the jobs you have created in production do not run in the sandbox, follow these steps


Full and Partial Sandboxes will continue to run scheduled jobs after refresh

If you've scheduled jobs to run in production, those jobs will also be scheduled to run in the sandbox. Follow our steps below to ensure your sandbox does not backup data to your production storage container

Create a Refresh Class

If you have not done so previously, you can create an apex class from a sandbox.

  1. From setup, search for Apex Classes in the quick find
  2. Click the New button
  3. Paste the following code into the editor
global class SandboxRefresh implements SandboxPostCopy {
  global void runApexClass(SandboxContext context) {
  // unschedule the grax apex jobs
    try {
        List<CronTrigger> jobs = [SELECT id,, State, NextFireTime
                                  FROM crontrigger 
                                  WHERE like '%GRAX%'];
        for (CronTrigger t : jobs){
    } catch (Exception ex){

    // Deactivate jobs & cancel any jobs in progress
      try {
          List<grax__grax_schedule_process__c> processes = [SELECT id, grax__is_running__c,
                                                            grax__status__c, grax__active__c
                                                            FROM grax__grax_schedule_process__c];
          for (grax__grax_schedule_process__c gsp : processes){
              gsp.grax__active__c = false;
              if (gsp.grax__is_running__c){
                  gsp.grax__status__c = 'Aborted';
          update processes;
      } catch (Exception ex){
  1. Click Save
  2. Migrate the class to your production Salesforce organization

Run the class when creating or refreshing a sandbox

When creating a new sandbox or refreshing an existing one, Salesforce allows you to specify an Apex Class that can run immediately after the sandbox is created.

Type the name of your apex class here. Our example is called SandboxRefresh but your class name may be different

Update Configuration

You will need to go back into your Configuration Setup (via GRAX --> Configuration --> Setup) and address any validation warnings presented there. Since Salesforce sandbox refreshes will result in the sandbox getting a new Org ID, you will most likely see the following warning when going to the Setup subtab:

Click on the Update Credentials button to review and re-save your configuration. This will save the Org ID for this newly refreshed sandbox into the GRAX configuration.