Apex · Salesforce

Find Sandbox Name from Your Sandbox Org

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();



    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;


    class SandBoxPostCopyExecutionTest {

    staticvoidtestSandboxPostCopyScript() {


    //Make sure you are populating dummy org id, sandbox id and sandbox name below
    new SandBoxPostCopyExecution(),



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


Reference Document:

SandboxPostCopy Interface

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s