I'm planning to query for the NameSpacePrefix field in my managed package as described here:

Organization Namespace using REST API

However because this was recently added (Spring '16) can I be sure this field will be available in my customers orgs? i.e. Are these releases rolled out globally or is it possible that a customer could be running an older version and then what would I do?

1 Answer 1


I would not use that because you need to understand that it is the Namespace of the organization .

Lets assume your org is Namespaced as "XYZ"(I assume you are packaging out of it) and your subscriber installs the app in the PROD or Sandbox and PROD or Sandbox wont have any namespace ,so that will be blank .

I queried in an org where I have mutiple packages installed and its value is blank .Although query returns a row .

So there is no question of using this in managed application .This seems good if you want to do something with Tooling or Metadata API where you need to know org namespace .

If you need namespace (most of times packaging org takes care of namespacing) then use below

global without sharing class CONSTANTS {
   public static final String CURRENTNAMESPACE = CONSTANTS.class.getName().substringBefore('CONSTANTS').removeEnd('.');
   public static final String CURRENTNAMESPACEPREFIX = (String.isEmpty(CURRENTNAMESPACE)) ? '' : CURRENTNAMESPACE + '__';
  • So, how can I figure out the namespace prefix of my managed package so I can make sure to construct my URLs correctly from my backend server? Aug 23, 2016 at 20:42
  • I think you misunderstood - I need the namespace passed to my server somehow during or after the Oauth call. I was trying to pass it in the state parameter but they said I was passing information "insecurely". So my idea was to make a SOQL call using the Apex API and get the package namespace that way. Aug 23, 2016 at 22:01
  • For that as well ,using organization name will not help you .since prod will have blank value .If you have a class part of managed package then the sample class I have should hell you Aug 23, 2016 at 23:42

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.