0
String endpointUrl = URL.getSalesforceBaseUrl().toExternalForm() +
                     + '/services/data/v38.0/tooling/query/? + 
                     + q=Select+Id,Name,SymbolTable,Body+From+ApexClass+where+Id= Apex class salesforce id';

I am able to get following information through above query using tooling api :

SymbolTable={constructors=(), externalReferences=(), id=01p2800000E0Fc2AAF, innerClasses=(), interfaces=(), key=01p2800000E0Fc2AAF, methods=({annotations=(), location={column=41, line=4}, modifiers=(static, public), name=getItems, parameters=(), references=(), returnType=LIST, type=null}, {annotations=(), location={column=35, line=12}, modifiers=(static, public), name=saveItem, parameters=({name=item, type=Camping_Item__c}), references=(), returnType=Camping_Item__c, type=null}), name=CampingListController, namespace=null, parentClass=, ...},

I want to fetch symbol Table field methods explicitly to know the methods in apex class and its parameters. Any idea how to parse the SymbolTable fields?

I have referred following document : link

0

If you feed the response payload into JSON2Apex, it will give you a bit of a beast. In this case, if you only care about method names, you can simplify it quite a bit. Here are the class definitions you would need in order to deserialize:

class QueryResult
{
    final List<Record> records;
}
class Record
{
    final SymbolTable symbolTable;
}
class SymbolTable
{
    final List<Method> methods;
}
class Method
{
    final String name;
    final List<Parameter> parameters;
}
class Parameter
{
    final String name, type;
}

If you plug the above into Execute Anonymous, you can add this script and get the method names for a particular class:

String baseUrl = URL.getSalesforceBaseUrl().toExternalForm();
String path = '/services/data/v38.0/tooling/query/?q=';
String query = 'Select+Id,Name,SymbolTable,Body+From+ApexClass+WHERE+Name=\'DML\'';

HttpRequest request = new HttpRequest();
request.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionId());
request.setEndpoint(baseUrl + path + query);
request.setMethod('GET');

QueryResult result = (QueryResult)JSON.deserialize(
    new Http().send(request).getBody(), QueryResult.class
);

List<Method> methods = result.records[0].symbolTable.methods;
// now you have all methods with their name and parameters

Set<String> methodNames = new Set<String>();
for (Method method : methods) methodNames.add(method.name);
// now you have unique method names

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.