I need to check the type of Sandbox to verify whether it is one of the following

  • Partial Copy Sandbox
  • Full Sandbox
  • Developer Sandbox

The Organization object helps in identifying if its a sandbox as follows:

[SELECT Id, isSandbox FROM Organization LIMIT 1].isSandbox

But, how to check the Type of Sandbox?

4 Answers 4


I don't think there's a straightforward solution.

As you've said, we have the Organization SObject which we can query to find certain environment information, such as:

SELECT Id, InstanceName, IsSandbox, Name, OrganizationType FROM Organization

This will tell us if we're on a sandbox environment, but it won't tell us which of sandbox it is.

The best solution I can offer is to include sandbox type in the sandbox type when creating them.

So if you have the following environments:

  • Prod: CompanyName
  • Sandbox: CompanyName.UAT
  • Sandbox: CompanyName.QA
  • Sandbox: CompanyName.DEV
  • Sandbox: CompanyName.DEVPRO

You will be able to query Organization.Name to find the current environment type.

It's pretty messy and requires the use of a naming convention in order to work, but I think it's the easiest way for now. Probably worth a post on the Ideas site, as it would be a pretty useful feature.


Depending on the name of your Sandbox, you could retrieve this information from the base URL.

Something like:

String baseURL = URL.getSalesforceBaseUrl().getHost();
String testPrefix = '--test';

Boolean isTestSandbox = baseURL.containsIgnoreCase(testPrefix);

System.debug('Value of baseURL: ' + baseURL);
System.debug('Value of isTestSandbox: ' + isTestSandbox);

Debug results:

[4]|DEBUG|Value of baseURL: companyname--test.csXX.my.salesforce.com [5]|DEBUG|Value of isTestSandbox: true


I have a use case where I want to create sample test data with a SandboxPostCopy class. It runs into this problem how do I know if it's a dev with no data or a partial or full with data.

I thought of the solution if you query for Account data, the probably most used object in the system, and if records are returned then you know it's a full or partial and if there are no records then it's a dev.


As we all know sandbox username looks like "[email protected] "

dev- is the sandbox name, How can we get it this dynamically ?

Use below code :-

if(UserInfo.getUserName().substringAfterLast('.com')!= null)
                    contact.Email = contactInfo.Email+'.'+UserInfo.getUserName().substringAfterLast('.');
                    contact.Email = contactInfo.Email;

UserInfo.getUserName().substringAfterLast('.') - will give you sandbox name.

UserInfo.getUserName().substringAfterLast('.com') will tell you whether anything is there after " .com ". if not there that means we are in production otherwise in sandbox. We can also used same method to identify type of org like prod or non prod. There is another approach for this.

Organization org = [select id,IsSandbox from Organization]; org.IsSandbox = true if it a sandbox. It willwork classs of higher version.

Feel free to suggest more.

  • if its a sandbox, how to check the type of sandbox?
    – ipradhansk
    Feb 18, 2016 at 7:49
  • This solution may not work if users change their username.
    – javanoob
    Feb 18, 2016 at 12:51
  • This doesn't answer the question, it only shows the name of the sandbox, not the type. Also only works if the current user's username ends in .com.
    – Ben
    Aug 3, 2016 at 18:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .