Welcome to my blog

I have been working with Salesforce for quite a while, so don’t hesitate to contact me if you have any questions or want some advice.

s f

Subscribe
Follow Us
h

Find Sandbox Name from Your Sandbox Org

 . Apex  . Find Sandbox Name from Your Sandbox Org

Find Sandbox Name from Your Sandbox Org

Learn How to Find Sandbox Name From Sandbox Org in Salesforce

Many of having trouble to find sandbox name from your Sandbox org. There is no direct way to get it but we have workaround. Please follow below steps

  1. Create list custom setting in your production org with Key and Value Pair like below 3-2-2018 2-58-59 PM
  2. Deploy below apex class code in to Production along with test class
global class SandBoxPostCopyExecution implements SandboxPostCopy {

    globalvoidrunApexClass(SandboxContextcontext) {

        String strSBName = context.sandboxName();
        updateConfigurationCustomSettingsWithSandboxName(strSBName);

    }
    globalvoidupdateConfigurationCustomSettingsWithSandboxName(StringstrSBName) {

        Configuration__c objConfiguration =Configuration__c.getValues(‘Sandbox Name’)
        if(objConfiguration ==null) {
        objConfiguration = new Configuration__c(Name = ‘Sandbox Name’, Value__c = strSBName);
        }
        else {
        objConfiguration.Value__c= strSBName;
        }
        upsert objConfiguration;

    }

}
@isTest
class SandBoxPostCopyExecutionTest {

    @isTest
    staticvoidtestSandboxPostCopyScript() {

        Test.startTest();

            //Make sure you are populating dummy org id, sandbox id and sandbox name below
            Test.testSandboxPostCopyScript(
            new SandBoxPostCopyExecution(),
            org.Id,
            sandbox.Id,
            ‘MySandboxName’
            );

        Test.stopTest();

    }

}
  1. call “SandBoxPostCopyExecution” apex class while refreshing your sandbox from production. Refer below image3-2-2018 3-23-11 PM
  2. Now after the sandbox refresh you have sandbox name in your sandbox environment custom settings.

Reference Document:

SandboxPostCopy Interface

Post a Comment