+ Start a Discussion
Etienne Coutant 6Etienne Coutant 6 

SandboxPostCopy not working for us


I created a class in my PROD environment that implements SandboxPostCopy. My undersating is that when I create/refresh a sandbox and specify my class, the code in that class will be executed upon creating/refreshing the sandbox.

Here is the code I am using for the SandboxPostCopy class.
global class SandboxRefreshCutover implements SandboxPostCopy {

    global void runApexClass(SandboxContext context) {

        System.debug('Sandbox copy done. ' + context.organizationId() + ' ' + context.sandboxId() + context.sandboxName());
        //Replace the URL endpoint in a Customer Setting
        Integration_Endpoints__c integrationEndpoint = Integration_Endpoints__c.getValues('TEST');
        if(integrationEndpoint != null)
            integrationEndpoint.URL__c = 'http://www.test.com';
            update integrationEndpoint;
            integrationEndpoint = new Integration_Endpoints__c(Name = 'TEST', URL__c = 'http://www.test.com');
            insert integrationEndpoint;

Now, I tried to create a few developer sandboxes and everytime the code is not executed.
Am I missing something?

Thanks a lot in advance.
I have checked and it should work.

You can get mored detail over here https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_interface_System_SandboxPostCopy.htm

Sandeep Singhal
Etienne Coutant 6Etienne Coutant 6

Thanks. I know it should work, but for some reason the values are not updated in the target sandbox as it should be... Seems like the code is not executed.

Emil Doverlind 6Emil Doverlind 6
Experience the same issue. The class that implements SandboxPostCopy does not seem to be executed on refresh nor create when specified in the section apex class.
The code that exist in runApexClass does work when I call it from unit test and apex anonymous.
Etienne Coutant 6Etienne Coutant 6
Thanks Emil!

Is there anyone who was able to create a class that implements SandboxPostCopy and have it executed correctly upon sandbox refresh???
I cannot create a Case for Salesforce as it requires Premium Support...

Emil Doverlind 6Emil Doverlind 6
I raised a case on Salesforce and this is the status, so far:
"R&D team has identified this issue as a bug and are working on it to fix the same"
Tony White (BNE)Tony White (BNE)
Anyone know if this has been fixed? or know where errors are logged when it fails?
Emil Doverlind 6Emil Doverlind 6
Apparently it is beeing rolled out as of now. Some orgs has the fix others do not. I did not see this issue in known issues, so you cant follow it there I am sorry.
Praneel PidikitiPraneel Pidikiti

Hello Emil & Tony,

I think the problem is the method should run in @future context. So in your runApexClass method call another method updatecustomsetting()
​public static void updatecustomsetting(){
and write the logic inside and this should work.
Tony White (BNE)Tony White (BNE)

I have a number of methods listed as that and none of them are getting run.
Would be curious to know if ANYONE has got this to work?

Tony White (BNE)Tony White (BNE)
Salesforce have now raised a Known Issue on this https://success.salesforce.com/issues_view?id=a1p300000008epFAAQ
Mohit SharmaMohit Sharma
Hi All,

I am curious to know, as we are in 2020, is this resolved? 
Becouse i am trying to implement this. 
Any workaround that has been provided for this issue. 
I will take that workaround in consideration while implementing my logic.