Sign up ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

I have a dev org, in which I have got a namespace prefix. In apex, I want to get this namespace prefix as string. Is there any straight way or I have to describe some object?

share|improve this question

2 Answers 2

up vote 7 down vote accepted

Query for it, using a class that you know will be there:

ApexClass myClass = [
    select NamespacePrefix
    from ApexClass
    where Name = 'SomeClassNameHere'
share|improve this answer

Unless I am missing something , this will work for managed package because MyClass will already have a namespace (our namespace). So that query will always return our namespace and not the org namespace where the app is installed.

share|improve this answer
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you have sufficient reputation you will be able to comment on any post. –  Eric Sep 29 at 21:57

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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