function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Gabriel WondersGabriel Wonders 

No such column NamespacePrefix on entity Organization

I'm getting the following error: No such column 'NamespacePrefix' on entity 'Organization'. When trying to save a class with the following SOQL query.
Organization org = [SELECT NamespacePrefix FROM Organization];
But I am able to run this query in the Developer Console Query Editor just fine. What's the reasoning behind this?
Best Answer chosen by Gabriel Wonders
Gabriel WondersGabriel Wonders
My mistake, I was working on a class that was set to API Version 30. The API version needs to be 36 or higher to use the field NamespacePrefix on the Organization object. 

All Answers

PrabhaPrabha
Did you have a package created on your Org?

I am able to save it in my DE. What type of Org are you trying it in?

If that is not working out, I recomment have a custom setting value and refer that in Apex. easy way out!!!

HTH,
Prabhan
Gabriel WondersGabriel Wonders
My mistake, I was working on a class that was set to API Version 30. The API version needs to be 36 or higher to use the field NamespacePrefix on the Organization object. 
This was selected as the best answer