I am making changes to an Apex controller class and something is not quite working.

I have added in some System.debug('message'); lines to see which logic gets executed, variable values, etc.

I then go to Environments > Logs > Debug Logs in the Lightning theme and there are 3 user trace logs, but all of them have an expiration date in the past. Could this be why no logs are apparently there?

Just trying to view a text/log file so I can see where things go awry.

  • Yes. Activation date can be maximum of one day. You need to set appropriate log level and should be active.
    – Raul
    Commented Mar 20, 2018 at 21:18

1 Answer 1


Salesforce always promotes using the Developer Console to view debug logs, but I prefer using the old school Setup > Debug Logs that you're looking at (which they don't even mention in the Trailhead module for debugging).


Yes, you need to set up a trace on the user who's running the code, and the logging duration is limited to 24 hours. The logs will appear in the Debug Logs section of Setup.

Don't be fooled by setting a class/trigger as the Entity, since that doesn't actually activate any logging. Only a user entity will cause logging to occur.

You can retain and manage debug logs for specific users, including yourself, and for classes and triggers. Setting class and trigger trace flags doesn’t cause logs to be generated or saved. 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. If logging is enabled when classes or triggers execute, logs are generated at the time of execution

I like to include a unique marker string like "###" in the System.debug() so I can find it easily when I'm viewing the log in my text editor. Example:

String x = 'abcd123';
System.debug('### var x is: ' + x);
  • Ok, I have created a new user trace log, type=user_debug, debug level is set to one I created which has Apex Code set to Debug. So using System.Debug should be fine, right?
    – andrewb
    Commented Mar 20, 2018 at 21:23
  • And then the log should appear in the debug logs section?
    – andrewb
    Commented Mar 20, 2018 at 21:24
  • I can see a log now but it doesn't include my .debug('') statements, just a lot of other info related to SQL queries and DML
    – andrewb
    Commented Mar 20, 2018 at 21:32
  • see my edited answer. Commented Mar 20, 2018 at 21:38
  • Good tip. My issue was the debug statements were not 'under' the controller name, but another name within the log list. thanks
    – andrewb
    Commented Mar 20, 2018 at 21:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .