function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Dave HagmanDave Hagman 

Execute Anonymous Apex using REST/Tooling API

Hey all,

    I have a question about the execute anonymous REST service:
/executeAnonymous/?anonymousBody=ANONYMOUSE_CODE_HERE

I need to also get the HEAP dump from the call, like the debug logs you receive when running anonymous from Developer Console/Eclipse/Mavens etc.

The only response I get is (in JSON):
{
  "line" : -1,
  "column" : -1,
  "compiled" : true,
  "success" : true,
  "compileProblem" : null,
  "exceptionStackTrace" : null,
  "exceptionMessage" : null
}


Has anyone ever done this or know how to do it? I have been scraping documentation for days with no luck. Thanks!
James LoghryJames Loghry
Good question!  Have you considered first querying for the available ApexLog records or HeapDumps prior to executing the anonymous apex, then querying for the next ApexLog / HeapDump in the list afterward?

Another thing to consider is possibly taking a look the ApexExecutionOverlay object.  Looks like you can specify a script and then get back the HeapDump in as a result.  Although, I'm not sure that behaves the same as execute anonymous. http://www.salesforce.com/us/developer/docs/api_tooling/Content/sforce_api_objects_apexexecutionoverlayaction.htm