I am currently having difficulty to add a new traceflag from APEX Trigger or Class.
Now, I've tried to use tooling API and using rest API call to activate a traceflag whenever new custom object gets created.
So that I can trace that user for certain period of time, record logs about user who is responsible for object creation.
No luck so far.
To tried to get around with this, I've used http callout inside of
@future(callout=true) class to avoid handling it from trigger, but this is what I get.
First error: You have uncommitted work pending. Please commit or rollback before calling out.
To be more precise, I am using below URL to attempt to create a new trace flag using REST API call.
URL.getSalesforceBaseUrl().toExternalForm() + '/services/data/v31.0/tooling/sobjects/TraceFlag'
Tooling API document regard with traceflag is linked below: