2

I am using this query using REST API to get Apex Classes SELECT Id,Name,NamespacePrefix,Status FROM ApexClass. However this returns all my classes as well Manage package classes.

How can I Identify that which classes are from my organization?

Is there any way to get Namespace of my Organization using REST API so that I can differentiate ?

I tried to parse response after OAuth however it does not have organization Namespace in it.

1 Answer 1

5

Spotted in the Spring `16 release notes under Changed Objects:

Organization

The following new fields have been added:

  • NamespacePrefix
  • SignupCountryIsoCode—Represents the two-character ISO country code specified by the user for a sign-up request.

It appears it will now be possible to directly query for the NamespacePrefix using SOQL

string np = [SELECT NamespacePrefix FROM Organization].NamespacePrefix;

As per Getting namespace prefix of an org, if you have a known class in the org then you can query the NamespacePrefix for just that and then find the other Apex classes with the same NamespacePrefix in a following query.

Other options:

  1. There are further options for a known ApexClass or custom object in Determining Namespace Prefix in JavaScript and Apex using the available metadata.
  2. When you query ApexClass the fields BodyCrc, Body, LengthWithoutComments come back with placeholder values if they aren't in your namespace. enter image description here. You can just filter out any results with, for example, BodyCrc = -1. I couldn't get these fields to work in a SOQL where clause, so you may need to filter in Apex with the query result.
0

You must log in to answer this question.

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