Latest Updates
Travel to Technology
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

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 image

2. Now after the sandbox refresh you have sandbox name in your sandbox environment custom settings.
Reference Document:
Our Recent Blogs
-
27 Jan, 2021
Salesforce Architect Domain Exam
-
23 Nov, 2016
Salesforce Certified Technical Architect New Path
-
28 Mar, 2018
Salesforce Release Exam in Trailhead Certification
-
29 Dec, 2021
Salesforce Certifications