I have an Apex Batch Class that I'm trying to view the debug logs for. I know that I can do this in the Dev Console, but the data and amount of logs its returning is causing the Dev Console to freeze. The approach I decided to take was create a TraceFlag for the class, but it appears that this doesn't actually save the logs for the class execution:

Class and trigger trace flags override other logging levels, including logging levels set by user trace flags, but they don’t cause logging to occur.

Source: (TraceFlag Help page)

I interpret this to mean that trace flags on ApexClasses do not actually save any of the logs of an apex class. Am correct in my understanding that you can only save logs at the user level?

Is there a recommended way to retrieve the logs for an Apex Class, specifically a Batch Class.


  • 3
    Does this answer your question? How are we supposed to use debug logs for a specific Apex class only – Kris Goncalves Jan 7 '20 at 16:58
  • Not quite. I have the trace flag set up for a basic batch class that just does debugs for the three methods (start, execute, and finish) to verify my trace is working. But I'm not getting any debug logs generated. I guess another question I have is: where are these logs saved once a tracer flag is set up? – thinker Jan 7 '20 at 17:49
  • 1
    If you read the comment, the trick is to put user trace flag with a debug level of "none" so the logs will be created and then set your class log to a debug level you want to override that. There will be a lot of 1kb irrelevant logs, but then you should see larger ones that are relevant only to the class. – Kris Goncalves Jan 7 '20 at 17:55
  • Ok, I see what you're saying. So then trace flags on Apex Classes are only for overriding the default log levels of a class. If you actually want to save logs, you can only do this for User Trace flags...??? – thinker Jan 7 '20 at 17:58
  • 1
    ah -- this is why all my batchables do custom logging to a persistent Custom Object so that when a production job runs, everything is captured for later analysis. I use the andyinthecloud Advanced Logging Patterns and corresponding github lib – cropredy Jan 7 '20 at 18:55

Class and trigger trace flags override other logging levels, including logging levels set by user trace flags, but they don’t cause logging to occur.

As you quoted, simply setting a class trace flag won't create a log. However, setting a user trace flag will and the class trace will override the user trace levels.

As explained in this helpful answer, the best you can do is the following:

  1. Put a User Trace Flag with all debug levels as "none". This will mean logs get created (which the class trace only does not do)
  2. Add the Class trace flag with the debug level that you want. This allows you, as you quoted, to override the settings you selected for the user trace flag (which was "none").

Now, you're left with logs getting created that would have very little to nothing (the user trace) and logs with actual information that would be the info related to the class trace.

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.