You need to sign in to do that
Don't have an account?
Polyglot
Execute Anonymous through the Tooling REST API
I'm writing an IDE plugin and I prefer using the REST API. For the Execute Anonymous resource:
http://domain/services/data/vXX.X/tooling/executeAnonymous/?anonymousBody=System.debug('Hello World');
The response is:
{"exceptionMessage":null,"compileProblem":null,"compiled":true,"exceptionStackTrace":null,"column":-1,"line":-1,"success":true}
How do I get access to the output/debug log?
http://domain/services/data/vXX.X/tooling/executeAnonymous/?anonymousBody=System.debug('Hello World');
The response is:
{"exceptionMessage":null,"compileProblem":null,"compiled":true,"exceptionStackTrace":null,"column":-1,"line":-1,"success":true}
How do I get access to the output/debug log?
To execute anonymous Apex:
req.setEndpoint('http://na1.salesforce.com/services/data/v28.0/tooling/executeAnonymous/?
anonymousBody=System.debug('Test')%3B');
req.setMethod('GET');
/sobjects/ApexLog/id/Body/
GET
Retrieves a raw debug log by ID. Available from API version 28.0 or later.
http://www.salesforce.com/us/developer/docs/api_tooling/Content/intro_rest_overview.htm
Regards,
Ashish
If we supply the ID of the class then we get the raw debug log.
Regards,
Ashish
The execute anonymous resource I'm invoking is: http://domain/services/data/vXX.X/tooling/executeAnonymous/?anonymousBody=System.debug('Hello World');
There is no Apex class involved - other than System. Does System have an Id?
Did you try this,
req.setEndpoint('http://na1.salesforce.com/services/data/v29.0/tooling/executeAnonymous/?anonymousBody=System.debug('Hello World');
req.setMethod('GET');
Replace the na1 with the server of your Org.
Regards,
Ashish
As I mentioned above, there is no straight forward way to do this in REST API. This can be done in 4 Steps:
Set Trace Flag : To log logs against your user
Endpoint : /services/data/v34.0/tooling/sobjects/traceFlag Method : POST Post: { "ApexCode": "Finest", "ApexProfiling": "Error", "Callout": "Error", "Database": "Error", "ExpirationDate": "2015-09-11", "TracedEntityId": "00590000000tQBwAAM", "Validation": "Error", "Visualforce": "Error", "Workflow": "Error", "ScopeId": null, "System": "Error" }
To know more about Trace Flag, go through this documentatation.
Run your executeAnonymous call through API.
Then, We need to make a query to get Id of raw log from ApexLog table. Run below query to get last log from user.
SELECT Id FROM ApexLog WHERE Request = 'API' AND Location = 'Monitoring' AND Operation like '%executeAnonymous%' AND LogUserId='00590000000tQBwAAM' ORDER BY StartTime DESC, Id DESC LIMIT 1
After getting Id, We need to make an another call for raw logs.
Endpoint: /services/data/v29.0/sobjects/ApexLog/07L9000004qMsoiEAC/Body Method: GET
(Optional) Remove trace flags from visibility.
-Ken