Tooling API execute anonymous results

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)
2. executeanonymous
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:

With Apex API (SOAP version) “executeAnonymous” process looks like so (pseudocode):

val apexCode: String = ...
val conn = getApexConnection
val debugHeader = new DebuggingHeader_element()
val res = conn.executeAnonymous(apexCode)
val log = conn.getDebuggingInfo.getDebugLog

Source : Link , Question Author : Kaushik Ray , Answer Author : gaiser

Leave a Comment