4

I am trying to get the references for methods defined in Apex Class via Tooling API ( by REST Call ). Please find the information of the REST Call below ( using Workbench )

Image

When i make the above REST call, i am able to get lot of information including "Symbol Table" but for all the classes references is coming as Null. But almost all the classes are being referred by some other class, so ideally it should be populated.

EDIT

Screenshot of the Symbol Table having Null References

enter image description here

enter image description here

Can anyone provide pointers why its not fetching the references?

  • Can you give an example of the JSON response you are getting please? Some snippets showing the null's perhaps? Note that jsonlint.com is great tool for formatting JSON to make it easier to read. – Andrew Fawcett Apr 14 '14 at 13:24
  • This post might help intmist.wordpress.com/2014/03/09/… @forcedeveloper – Ashwani Apr 14 '14 at 17:34
  • @AndrewFawcett Updated the Question with the screenshot of the response...Please let me if you need any other information regarding this..Appreciate your help on this. – ForceDeveloper Apr 15 '14 at 4:57
5

RE: Mystery "type" field

The Tooling API documentation is a little shallow in this area, it does not go into the specific meaning of all the fields returned. I don't see any description for the "type" field, which i can see is null indeed give your test Apex class use case. I sometimes find reviewing the WSDL for the SOAP version of the Tooling API helpful, sometimes we find the fields has some enum values, though not so in this case.

<xsd:complexType name="Symbol">
 <xsd:sequence>
  <xsd:element name="location" type="tns:Position"/>
  <xsd:element name="modifiers" minOccurs="0" maxOccurs="unbounded" type="xsd:string"/>
  <xsd:element name="name" type="xsd:string"/>
  <xsd:element name="references" minOccurs="0" maxOccurs="unbounded" type="tns:Position"/>
  <xsd:element name="type" type="xsd:string"/>
 </xsd:sequence>
</xsd:complexType>

To understand what this field might represent take a look at how the above XML Schema type is used throughout the XML Schema in the WSDL, eventually if you follow the type inheritance, you will see that "VisibilitySymbol" extends it, and that this type is in fact used in to also represent Apex properties in the SymbolTable, which i assume your test Apex class does not have? As the "properties" field is not present above. In this case as you can see below the "type" field is present and describes the Apex data type of the property.

public with sharing class SymbolTableTest {

    public SymbolTableTest() {

    }

    public String PropertyA { get; set; }

    public String methodA(String parameterA)
    {
        return PropertyA;
    }

    public String methodB(String parameterA)
    {
        return methodA(parameterA);
    }

}

enter image description here

RE: Presence of External references

As per the documentation on the ApexClass object in the Tooling API documentation, this information is not present.

If there is not a cached version of SymbolTable, it will be compiled in the background and the query might take longer than expected. The SymbolTable returned from ApexClass does not contain references; to retrieve a SymbolTable with references, use ApexClassMember.

It is only populated when you query the ApexClassMember object. The downside here is you can only access the ApexClassMember Symbol Table after you have performed a compile, which requires learning about MetadataContainer's and another object called ContainerAysncRequest. If you review the MetadataContainer documentation there is a summary of the process at the bottom of the topic. Note that is an async process and thus requires some polling approach in your code as well. If you want to see the process in code you can review the code for the Apex UML open source tool here, although the code is Apex, the process and steps to call the REST API are the same.

  • Ahh....i missed that in the documentation..Is there any way to do REST API call for "ApexClassMember", when i make a REST call with the id of the Apex Class its not working ( /services/data/v29.0/tooling/sobjects/ApexClassMember/01p90000003YLXT )...But it when you do make a call like this ( /services/data/v29.0/tooling/sobjects/ApexClassMember/ ) in response it provides the response with the URLs which suggest that way – ForceDeveloper Apr 15 '14 at 11:34
  • No you cannot use the same Id for ApexClassMember, its a different object, you need to create a record in this object, associating it with a MetadataContainer record, then create a Container AsyncRequest to have the platform background compile, once that is done you re-query the ApexClassMember record and your extenral references are in the Symbol table. – Andrew Fawcett Apr 15 '14 at 14:01
  • 1
    Appreciate your time on this...Like always excellent piece of information regarding the issue. – ForceDeveloper Apr 16 '14 at 11:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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