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
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. – Salesforce Developer Dec 20 '14 at 14:05

1 Answer 1

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

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.