2

How to send a TaceFlag using the Tooling REST Api?I am looking for a good REST example how to setup Traceflag and get how to get Traceflag results back?

1

Here is one example that you can invoke right from the developer console. This creates a traceflag on an User.

I have an example with 1 hard-coded value. If I do this outside the Apex environment, I can query that value as well. The hardcoded value is for DebugLevel.

I hope this helps.

String userToTrace = System.UserInfo.getUserId();
String endPoint = URL.getSalesforceBaseUrl().toExternalForm()+'/services/data/v36.0/tooling/sobjects/TraceFlag/';

HttpRequest req; 
HttpResponse res; 
Http h; 

req = new HttpRequest(); 
req.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionID()); 
req.setHeader('Content-Type', 'application/json'); 
req.setEndpoint(endPoint); 
req.setMethod('POST'); 
req.setBody('{"TracedEntityId":"' + userToTrace + '","LogType":"USER_DEBUG","DebugLevelId":"7dl700000008ONeAAM"}'); 
h = new Http(); 
res = h.send(req); 
System.debug(res.getBody()); 

One more thing, I had to white-list my salesforce domain url in the Remote Site settings. There is also another parameter that the traceflag payload can accept. That is expiration date. You may want to set an Expiration date when you do this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.