I am trying to run an execute anonymous statement using tooling API.
I am running a very simple
Now the issue is as this is a GET request, the response that I get is like this –
How can I get the results of my code execution to be displayed in my called UI.?
if you want to see a debug output then you need to get it separately.
With Tooling API it involves:
1. Seting TraceFlag
2. Downloading log file
An example flow can be something like this:
1. Create TraceFlag (this is to tell SFDC to start logging)
3. retrieve debug log
4. delete TraceFlag
step 4 is not strictly necessary but helps keeping things clean.
Also, I am not sure if your use case demands REST specifically and SOAP is a no go, but if you could use SOAP API then you might want to look into SOAP API Developer’s Guide.
With Apex SOAP API you do not have to go through as many steps as with Tooling API to get a debug log.
Have a look at the DebuggingHeader documentation: https://developer.salesforce.com/docs/atlas.en-us.196.0.apexcode.meta/apexcode/sforce_api_header_debuggingheader.htm
With Apex API (SOAP version) “executeAnonymous” process looks like so (pseudocode):
val apexCode: String = ... val conn = getApexConnection val debugHeader = new DebuggingHeader_element() debugHeader.setDebugLevel("Debugonly") conn.__setDebuggingHeader(debugHeader) val res = conn.executeAnonymous(apexCode) val log = conn.getDebuggingInfo.getDebugLog