I was trying to get sandbox name in my apex for logging purposes. I didn't find any direct way and hence I did the following using IsSandbox from Organization object,

    String envName = '';
    Organization org = [SELECT IsSandbox FROM Organization];
        envName = UserInfo.getUserName().substringAfterLast('.');
    }else if(!org.IsSandbox){
        envName = 'PROD';  

Does the query on Organization object count against the query limit or is it exempt similar to custom metadata type?


Any SOQL queries except Custom Metadata queries, written in Apex code are counted against SOQL limits. So your query will be counted. You can try running the above code in Developer console to cross verify it.

I tried running your code in developer console it does gets counted in Standard Governor Limits.

enter image description here

| improve this answer | |
  • 1
    Any SOQL queries -- except Custom Metadata queries. – sfdcfox Dec 17 '19 at 17:16
  • Yeah, thanks for the correction. I'll update the answer. – Rohit Mourya Dec 17 '19 at 17:17

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.