We are trying to automate certail processes for which we need to find the dependent components for a Class/Page/Trigger.
We understand that salesforce is providing dependent components using "Show Dependencies" button when respective components are viewed but is there a way to get these programatically?
(This was posted in Stakeoverflow and got the response to use SymbolTable and look for external references - https://stackoverflow.com/questions/27367493/how-to-find-dependent-components-for-a-class-page-trigger-using-api-tooling-or)
I tried following steps to access SymbolTable.
- Created a Connection
- Created a MetadataContainer using POST (Tooling API) with Name as Compile.
- Queried MyPageController class, got the Id, Name and Body from ApexClass.
- Created ApexClassMember using POST (Tooling API) with MetadataContainerId set to the id from Step 2, ContentEntityID set to class id from step 3, Body set to body from step 3.
- Created ContainerAsyncRequest to compile the class with MetadataContainerId set to id from step 2 and IsCheckOnly to true. (Tried false also). The compilation was successful as the response State is 'Completed'.
- After successful compilation, tried querying ApexClass for SymbolTable, I am getting the data but not ExternalReferences. (We should query ApexClassMember to access SymbolTable, not the ApexClass)
When I check the same class in developer console, I am able to see the 4 related components, 1 Apex Page and 3 Classes.
Am I doing anything wrong, unable to figure out what mistake i am doing. Any pointers is much appreciated.
Thanks!
Code: https://github.com/bugude/SalesforceDeveloperOrgRespositories/blob/master/TestSymbolTable.java