Inside a formula field I want to be able to determine whether the org is the production org or a full copy sandbox. After researching I came up with this:

IF($Organization.Id = 'XXXXXXXXXXX', "PROD", "FULL SANDBOX")

However it appears that a full copy sandbox takes the id from the production org as well.

Originally I wanted to use $Organization.IsSandbox but that field is not accessible within the formula fields.

  • As far as I know, there's still no reliable way to know what type of sandbox you're in. You can only figure out if you are, or are not, in a sandbox, and even then, not in all types of formulas.
    – sfdcfox
    Nov 30, 2017 at 8:11

3 Answers 3


When I asked how to Differentiate Production/Sandbox Instance? I ended up following a strategy of parsing the username. Somewhat brittle, perhaps, but it should work for the majority of your users. If you add this field detection at the user level, then you will be able to merge $User.Is_Production__c into just about any formula in the system.

You could certainly adapt this solution to your needs with a formula that renders everything after @mycompany.com. as the approximate sandbox name.

RIGHT(Username, LEN(Username) - LEN("@mycompany.com") - FIND("@mycompany.com.", Username))

Then you can reference $User.Sandbox_Name__c = "MyFullSandbox" in your formulas, for example. You could probably make this solution more robust by blending the approach with SandboxPostCopy and Hierarchy Custom Settings, taking the most common value amongst all users and storing that as the org default.


I am thinking about a complecated way of how can you detect a sandbox.

  • Create hierarchy custom setting with field isSandbox
  • Create class that implements SandboxPostCopy Interface. This class populates hierarchy custom setting on company level isSandbox as true
  • on each sandbox refreshing or creation process you need to specify "Apex Class" from previous point at last step.

After that it is possible to reference hierarchy custom setting in field formulas in the following way: $Setup.CustomSettingName__c.CustomFieldName__c


You can use $Api.Enterprise_Server_URL_500 to get the url and then see if it contains your production or sandbox name.

if( CONTAINS($Api.Enterprise_Server_URL_500, 'fullsand'),'sandbox','production') or just leave it as binary. You can also do this to have dynamic urls when using sandbox links.

Just make sure that the url has the contains clause. it get a little funky if you have a lot of sandboxes.

You must log in to answer this question.

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