4

I've just started working with ApexClass.SymbolTable from the ToolingAPI. In the documentation, a SymbolTable entry contains properties, variables, and methods which have parameters. The documentation doesn't show a way to get Type information about properties, variables, or parameters, but the API result includes a type property for each.

All of the variables in my symbol table which represent collections include the full parameterized type, e.g., List<String> or List<ApexClass.InnerType>. But all of the properties and method parameters only show the non-parameterized List type.

Example Variable:

{
  "annotations": [ ], 
  "location": {
    "column": 49, 
    "line": 52
  }, 
  "modifiers": [ ], 
  "name": "fields", 
  "references": [ ], 
  "type": "List<Schema.SObjectField>"
}, 

Example property:

{
    "annotations": [ ], 
    "location": {
        "column": 32, 
        "line": 18
    }, 
    "modifiers": [
        "private"
    ], 
    "name": "sortSpecs", 
    "references": [ ], 
    "type": "List"
},  

Not sure why it should matter, but I'm fetching these results with Workbench, just to inspect the SymbolTable result.

Is this a known issue? A bug? I've been able to find almost no documentation of SymbolTable beyond the page in the Tooling API docs, nor any report of this issue. Is it possible to get the full type info for any List property?

2

1 Answer 1

4

It's a short coming of the SymbolTable API design. I'd suggest raising an idea to expand out the parameterized type information.


There is one more complicated option you can do for parameters. Take the example class below:

public class TakesListParameter {
    
    public List<String> listOfAccountNames = new List<String>();
    
    public List<Decimal> amountsProperty { get; set; }
    
    public void doCalculation(List<Integer> inputNumbers) {
        listOfAccountNames = new List<String>();
        amountsProperty = new List<Decimal>();
    }
    
    public List<String> getValues() {
        return new List<String>();
    }
}

Under methods you will see doCalculation as:

{
        "annotations": [],
        "location": {
            "column": 17,
            "line": 7
        },
        "modifiers": ["public"],
        "name": "doCalculation",
        "parameters": [{
                "name": "inputNumbers",
                "type": "List"
            }
        ],
        "references": [],
        "returnType": "void",
        "type": null
}, 

As you observed, the parameter type is just "List".

Further down in the SymbolTable is the "variables" section. In that you will find:

{
    "annotations": [],
    "location": {
        "column": 45,
        "line": 7
    },
    "modifiers": [],
    "name": "inputNumbers",
    "references": [],
    "type": "List<Integer>"
}

Note that between the name and the line number this is the same input parameter, and includes the full type information.

Unfortunately this won't help you for properties or return types. As above, raise an idea exchange post out to expand the parameterized type information would be helpful.


For reference, anonymous Apex code to get the symbol table for a class:

HttpRequest request = new HttpRequest();
Id testClassId = [Select Id from ApexClass where Name = 'TakesListParameter'].Id;
request.setEndpoint(URL.getOrgDomainUrl().toExternalForm() + '/services/data/v56.0/tooling/query/?q=Select+Id,Name,SymbolTable+From+ApexClass+where+Id=\''+testClassId+'\'');
request.setMethod('GET');
request.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionId());
request.setHeader('Accept', 'application/json');
request.setTimeout(10000);

HttpResponse response = new Http().send(request);
System.debug(response.getBody());

You must log in to answer this question.

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