Problem
/services/data/v36.0/tooling/query/q=Select+Id,Name,SymbolTable+From+ApexClass+where+Name+in+(‘MyApexClass’,’MyApexClassTwo’)
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’?
Solution
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:
- Create a MetadataContainer record with a unique name. Record the MetadataContainerId
- 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.
- Create a ContainterAsyncRequest for the MetadataContainerId. Use the IsCheckOnly option to avoid making changes.
- Keep retrieving the State until it is no longer Queued.
- Retrieve the ApexClassMember with the SymbolTable.