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
Ken Koellner @ EngagewareKen Koellner @ Engageware 

How to get Debug Log Body with SOAP Tooling API?

We have an existing testing utility that uses the Tooling API.  It is written using the SOAP version, not the REST version.  I know I can query for the latest log for the user.  I know there is a REST API to get the debug log body.  But, I'd rather not have to recode using REST or mix REST/SOAP if I don't have to. 

I tried the example below.  The getDebuggingInfo() call returns null.  If I got that back, I could call getDebugLog() on that to get the body.  The comments at the end are simply notes of where I would start if I wanted to mix in REST.
com.sforce.soap.tooling.LogInfo[] logList = new com.sforce.soap.tooling.LogInfo[1];
        logList[0] = new com.sforce.soap.tooling.LogInfo();
        logList[0].setCategory(com.sforce.soap.tooling.LogCategory.Apex_code);
        logList[0].setLevel(com.sforce.soap.tooling.LogCategoryLevel.Fine);        
        ExecuteAnonymousResult apexResult = conn.executeAnonymous ("System.debug('Hello.');");
        System.out.println(apexResult);
        com.sforce.soap.tooling.DebuggingInfo_element debuggingInfo = conn.getDebuggingInfo();
        System.out.println(debuggingInfo);
        com.sforce.soap.tooling.GetUserInfoResult userResult = conn.getUserInfo();
        String userId = userResult.getUserId();
        System.out.println(userId);
        // SELECT Id FROM ApexLog WHERE LogUserId = userId ORDER BY LastModifiedDate DESC LIMIT 1
        // /services/data/v49.0/sobjects/ApexLog/07L4p00000FU34uEAD/Body

Below is the output --
[ExecuteAnonymousResult  column='-1'
 compileProblem='null'
 compiled='true'
 exceptionMessage='null'
 exceptionStackTrace='null'
 line='-1'
 success='true'
]

null
005460000010bMfAA

Anyone know a way to get the Debug Log body with SOAP?  Or am I going to have to mix in a REST request?  Or maybe the flags aren't set properly to get the log and that's why getDebuggingInfo is returning null?
 
ShirishaShirisha (Salesforce Developers) 
Hi Ken,

Greetings!

Have you checked the below thread which has sample code to get the debug logs using SOAP.

https://salesforce.stackexchange.com/questions/41837/get-debug-logs-with-specified-log-levels-for-execute-anonyous-via-apex-toolingap

Kindly mark it as best answer if it helps so that it can help others in the future.

Warm Regards,
Shirisha Pathuri
Ken Koellner @ EngagewareKen Koellner @ Engageware
The programmer was using Apex to call back to the Tooling API as a Remote Site.  I'm using Java.  But it looks like the result is the same.
Note that comment--
This was partially successful. The CALLOUT_RESPONSE did have a <soapenv:Header><DebuggingInfo><debugLog> in the response. However, this wasn't populated into the DebuggingInfo property in Apex.
The issue I'm gettng is getDebuggingInfo() returned null.  If you look at the raw soap, it's likely as the other programmer said in the above comment.

I found some much older posts with some info on it but they were out of date.  I wonder is SF just simply removed that capability in the SOAP API many releases ago.

So, thanks for the response but it doesn't move any closer to an solution.