The Tooling API brings a new object with it, that allows me to create Apex Logs programmatically. It's called TraceFlag. I tried to implement it in my na15 org (28.0) but i get a

No access to entity: TraceFlag


I just use Developer's Guide code:

    TraceFlag traceFlag = new TraceFlag();
    traceFlag.ApexCode = 'Finest' ;
    traceFlag.ApexProfiling = 'Finest' ;
    traceFlag.Callout = 'Info' ;
    traceFlag.Database = 'Finest' ;
    traceFlag.System = 'Debug' ;
    traceFlag.Validation = 'Info' ;
    traceFlag.Visualforce = 'Info' ;
    traceFlag.Workflow = 'Info' ;
    //set an expiration date
    traceFlag.ExpirationDate = myTimestamp;
    //set the ID of the user to monitor 
    traceFlag.TracedEntityId = runAs.Id ;
    //call the create method 
    TraceFlag[] traceFlags =new TraceFlag[] {traceFlag};
    SaveResult[] traceResults = sforce.create(traceFlags);
    for ( int i = 0; i < traceResults.Length; i++)
        if (traceResults[i].success) {
           System.debug( 'Successfully created trace flag: ' + traceResults[i].id);
        else {
            System.debug( 'Error: could not create trace flag ' );
            System.debug( ' The error reported was: ' +
                            traceResults[i].errors[0].message + '\n' );

Do I need to create it via REST API?

1 Answer 1


Please remember that the Tooling API is meant to be called from outside Salesforce.com. The examples in the Summer '13 docs look like Apex but as far as I know this is a JAVA exampple.

If you want to use features of the Tooling API from inside Apex you first need to learn how to call this API from APEX.

Maybe those questions / web articles help in doing that:

  • 1
    but look what I found on StackExchange: "The naming of the ToolingAPI is a little confusing. It's really just a new set of components (sObjects for the most part) that are layered on top of the standard REST or SOAP APIs."[@Ralph] (And it's not even possible to declarate a null TraceFlag object)
    – Basti
    Jun 17, 2013 at 15:12

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.