3

I am trying to get methods references and external references using REST version of the Tooling API, but they all = null:

/services/data/v36.0/tooling/query/q=Select+Id,Name,SymbolTable+From+ApexClass+where+Name+in+('MyApexClass','MyApexClassTwo')

enter image description here

public with sharing class MyApexClass {

public void testA(){}

public void testB(){
    testA();
}
}

public with sharing class MyApexClassTwo {

public void testC(){
    MyApexClass mac = new MyApexClass();
    mac.testB();
}
}

Why all references = null, if I call testA() in testB() in class 'MyApexClass' and then tesB() in testC() in external class 'MyApexClassTwo'?

EDIT 1: Okay, I find my mistake The SymbolTable returned from ApexClass does not contain references; to retrieve a SymbolTable with references, use ApexClassMember. But how can we create ApexClassMember?

1 Answer 1

3

As you have found, you need to use an ApexClassMember to access the full SymbolTable.

The ApexClassMember's often don't exist for the class of interest, so you must create them. The same with ApexTriggerMember records.

General steps to get the SymbolTable:

  1. Create a MetadataContainer record with a unique name. Record the MetadataContainerId
  2. Create a collection of ApexClassMember records referencing the MetadataContainerId. Populate the Body for each ApexClassMember with the corresponding ApexClass body. Populate the ContentEntityId with the Apex Class ID.
  3. Create a ContainterAsyncRequest for the MetadataContainerId. Use the IsCheckOnly option to avoid making changes.
  4. Keep retrieving the State until it is no longer Queued.
  5. Retrieve the ApexClassMember with the SymbolTable.
1

You must log in to answer this question.

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