11

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?

  • This is on my to do list. – AtulRajguru9 Mar 1 '16 at 8:55
  • @AtulRajguru9 Well, if you get it working, let me know if there are any tricks to getting it set up. I'll see if I can't figure it out myself, but it's hard to use brute force trial and error when each sandbox refresh takes so long. – martin Mar 1 '16 at 11:44
  • 1
    @martin Have you tried using 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. – Daniel Ballinger Mar 1 '16 at 20:05
  • @DanielBallinger Good idea, my sandbox post refresh code previously had 0% test coverage. I created a test class and the test ran successfully in both the sandbox and in prod, and the debug logs showed that the account was inserted. However, after refreshing a sandbox, I still didn't see that account created. – martin Mar 2 '16 at 3:13
4

I had the same issue and raised a ticket for Salesforce support team.

They came back saying there is a bug at their end and they are working on fixing it. Fix is expected to be available by end of next week (safe harbor).

Here is the response I got from Salesforce Support team.

Hi Arpit,

Hope you are doing good.

I would like to inform you that our R&D team has identified this issue as a bug and are working on it to fix the same. I'll keep you posted of further updates on this one.

Regards
Ayush Sodhi
Success Agent- Tier 2

  • Thanks for your post. It looks like they took a bit longer than they expected to get this up and running, but in my most recent sandbox refresh on April 7th, the script worked. – martin Apr 8 '16 at 1:50
  • Has anyone gotten this to work now that the bug fix was released with Patch 16 this week? We are still having the same problem we were having before the patch was released. Run the code manually, and it works. Refresh the sandbox, and the code runs, no error, but no data. Debug log stops at the DML statement that inserts the accounts. – Lisa Apr 8 '16 at 16:12
1

Nearly a year later, I'm wondering whether @Lisa or anyone else has been able to create accounts successfully..? I'm trying to create a post copy process that recreates the test data that one of our teams relies on, and which is painful to reproduce manually. I thought all was well 'til that first

   "System.TypeException: DML operation INSERT not allowed on Account"

appeared and yes, still only after deploying to Production and refreshing a sandbox. Thankfully, they only need a dev sandbox, and it only requires a day between attempts. But if the result is still going to be "No", it'd be good to now today, y'know...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.