So in visualforce I can access all kinds of organization variables like:



Now what I need is to determine if a user is in a sandbox. Organization object has the very legitimate field 'IsSandbox'. But doing '{!$Organization.IsSandbox}' results in a push error saying IsSandbox field does not exist. I have API version of 45 on my visualforce component that is trying to do this.

Did they really not allow access to IsSandbox from visualforce? Is there any other way to do this? I don't want to create a controller JUST to get the IsSandbox flag from a query...

  • The docs specify that it has to be queried. I can't fathom why it's not available as a regular old global variable, so we can use it in formula fields, flow, etc. Also. – gorav Jul 19 at 23:46

From the documentation of $Organization it's quite clear that possible values are


It does not contain IsSandbox so you have to look for alternative.

Based on my Limited knowledge of VF I can say we can use AJAX Toolkit in VF.

AJAX Toolkit allows you to query any record and use JS to alter HTML and post your content.

Your code will be like:

<apex:page >
    <script type="text/javascript">
    var __sfdcSessionId = '{!GETSESSIONID()}';
    <script src="../../soap/ajax/46.0/connection.js"
    <script type="text/javascript">     window.onload = setupPage;
    function setupPage() {
      //function contains all code to execute after page is rendered

      var state = { //state that you need when the callback is called
          output : document.getElementById("output"),
          startTime : new Date().getTime()};

      var callback = {
          //call layoutResult if the request is successful
          onSuccess: layoutResults,

          //call queryFailed if the api request fails
          onFailure: queryFailed,
          source: state};

          "Select Id,isSandbox FROM Organization",

  function queryFailed(error, source) {
    source.output.innerHTML = "An error has occurred: " + error;

  * This method will be called when the toolkit receives a successful
  * response from the server.
  * @queryResult - result that server returned
  * @source - state passed into the query method call.
  function layoutResults(queryResult, source) {
    if (queryResult.size > 0) {
      var output = "";

      //get the records array
      var records = queryResult.getArray('records');
      output = 'Is Sandbox '+ records[0].IsSandbox;
    source.output.innerHTML = output;

    <div id="output"> </div>


Src: https://developer.salesforce.com/docs/atlas.en-us.ajax.meta/ajax/sforce_api_ajax_vf_sample.htm

  • Similar to what I would have wrote, but using apex:remoteObjects instead. – sfdcfox Jul 19 at 16:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.