By querying the ApexClass object, one can list all the classes that exist within an organization. However, if the code which queries the classes is from a managed packaged, can it see all the records, or just the classes that are part of the package? Also, can it see another package class?

Considering the case where, in a subscriber org, you have the default namespace and two packages installed, can one of those packages read all the ApexClass records in the organization (and by reading I mean just acknowledging that the class/record exist, not reading its contents).

SELECT Id, Name, NamespacePrefix FROM ApexClass

would return a list like:

01p000000000000AAA | DefaultNSClass | 
01p000000000001AAA | AnotherNSClass | anotherns
01p000000000002AAA | PackageNSClass | mypackagens

1 Answer 1


If the class you're interested in looking for is global, you can save a query by using Type.forName(namespacePrefix, className). In all other cases, you should be able to at least query for the given ApexClass to confirm its presence, but you won't be able to interact with it in any way.

  • That's fine. I just need to know that it exists, and its name. Getting the content would be helpful, but it is not necessary. I'm particularly interested in the ApexTestQueueItem object for this situation. A package that can query classes and pass their Ids to a test queue. Commented Aug 31, 2018 at 17:53
  • @RenatoOliveira Yeah, though, unfortunately, there isn't a way to determine if the class is a test class (or not), so you'll have to create a bunch of bogus entries to make sure you don't miss anything.
    – sfdcfox
    Commented Aug 31, 2018 at 18:03
  • Exactly. While a good filter can be made by detecting the "Test" word in the class' name, I think it is a better approach to allow the user to select the class himself. At least for now... maybe in the future we get a "IsTest" field to query. Commented Aug 31, 2018 at 18:05
  • @RenatoOliveira Yeah, I just tried a SOSL, just to be sure, and no dice there, either.
    – sfdcfox
    Commented Aug 31, 2018 at 18:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .