1

I am interested in being able to get information about classes, specifically variables, methods etc. I see this can be done by the Tooling API, what I am not clear on is if I need to make an API call to do this even when I am in my developer instance?

In other words, is there no way to directly query this information without the API call? I see in the Query Editor there is a checkbox for "Use Tooling API" right next to the Execute button.

When I select this checkbox I can directly query the symbol table of an object in the query editor, so I am thinking there must be a way to do this from withing a class without the API call?

All the documentation I have found if for using this with the API call however...

3
  • 1
    While there is an ApexClass object that you can use SOQL to query, the symbol table detail is only exposed via the Tooling API. However you can invoke that from Apex code - see Apex Tooling API - SOAP Edition. You may also find useful information and links in this post How can I find unused methods and variables?.
    – Keith C
    Mar 29 '16 at 16:22
  • Thanks, that got me started. I guess I can't mark a comment as an answer?
    – ScottH7a9
    Mar 30 '16 at 16:52
  • No but you can answer your own question for other people's reference in the future; think you have to wait a day before you an accept your own answer though.
    – Keith C
    Mar 30 '16 at 16:57
0

As Keith commented, you can't directly access the ApexClass in Apex as it is exposed via the Tooling API. The version that the Partner API and Apex have access to doesn't have include the SymbolTable field.

Instead, you will need to callout to the Tooling API from Apex. One easy way to do this is to use the Apex Tooling API wrapper created by Andrew Fawcett. This will simplify actual process of making the callout and processing the response.

I've added example code in the answer to your other question - Symbol Table from Apex Class

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