SfSkills Domains Docs GitHub

Home / apex / debug-logs-and-developer-console

debug-logs-and-developer-console

Use when setting up debug logs and trace flags, reading Apex log output and log levels, running queries in the Developer Console, executing anonymous Apex, or using the Apex Replay Debugger in VS Code. Triggers: 'set up debug log', 'Developer Console', 'anonymous Apex', 'trace flag', 'Apex Replay Debugger', 'tail Apex logs from the CLI', 'capture logs for a platform event trigger'. NOT for production logging strategy or custom structured logging frameworks — use apex/debug-and-logging. NOT for writing test classes — use apex/test-class-standards.

Open the skill folder on GitHub


Use this skill when a developer needs to capture runtime Apex behavior with debug logs, use the Developer Console or the sf CLI to read them, run anonymous Apex, or step through a log with the Apex Replay Debugger. It covers the native debugging toolchain, not logging architecture or production observability.


Before Starting


Questions to Ask Before Configuring

QuestionWhy it mattersWhat a good answer addsWhat proper configuration adds over just doing it
"Which user, or which background process, runs the code we need to see?"Event triggers and resumed flows log under Automated Process, and those logs don't show in the Developer Console Logs tabThe right traced entity: the user, Automated Process, or the overridden trigger userA log that actually appears after the reproduction
"Do we need more detail for one class or trigger without flooding the whole log?"CLASS_TRACING trace flags override levels for that class or trigger but don't generate logsA user (or Automated Process) trace flag plus a class trace flag with higher levelsA focused log that stays under 20 MB
"When will the problem be reproduced, and for how long must logging run?"Expiration must be under 24 hours from start, and trace flags expire without warningA window that brackets the reproductionNo empty searches after a flag quietly expired
"Could the code under trace touch passwords, tokens, or personal data?"FINEST on Apex Code logs all variable assignmentsLower Apex Code levels, or a sandbox with masked dataNo secrets sitting in a downloadable log
"Is a deployment running while the Developer Console is open?"Developer Console log levels affect all logs, including deployment logs, and FINEST slows deploymentsClose the Console or lower levels before deployingDeployments that are not slowed by logging
"How many logs will this generate?"More than 1,000 MB in 15 minutes disables trace flags; more than 1,000 MB stored blocks new trace flagsA narrow window and a cleanup stepLogging that keeps working for the rest of the team

What a proper setup adds over clicking "New" in Debug Logs: the log lands under the right entity, contains the detail you need, stays under the size cap, and does not leak sensitive values or block other people's trace flags.


Core Concepts

Trace flags and debug levels

A trace flag (Tooling API TraceFlag) ties a traced entity (TracedEntityId: a user, an Apex class, or an Apex trigger) to a debug level for a time window. LogType is one of:

LogTypeWhat it does
USER_DEBUGLogs an individual user's activities
DEVELOPER_LOGSet by the Developer Console when it opens, and by sf apex tail log, to log your own activity
CLASS_TRACINGOverrides levels for an Apex class or trigger; doesn't generate logs

A debug level (Tooling API DebugLevel) holds one level per category. The Apex Developer Guide lists these categories: Database, Database Access, Workflow, NBA, Validation, Callout, Apex Code, Apex Profiling, Visualforce, System. Levels run NONE, ERROR, WARN, INFO, DEBUG, FINE, FINER, FINEST, and are cumulative. Not every category offers every level.

Order of precedence

  1. Trace flags override all other logging logic.
  2. With no active trace flags, Apex tests run with default levels (DB INFO, APEX_CODE DEBUG, APEX_PROFILING INFO, WORKFLOW INFO, VALIDATION INFO, CALLOUT INFO, VISUALFORCE INFO, SYSTEM DEBUG).
  3. Otherwise the API header sets levels; API requests without debugging headers produce transient logs that aren't saved.
  4. Otherwise an entry point's own level applies. If none apply, no log is generated.

Limits and retention

LimitValue
Size per log20 MB; larger logs lose older lines from any location
RetentionSystem debug logs 24 hours; monitoring debug logs seven days
BurstMore than 1,000 MB of logs in 15 minutes disables trace flags (re-enable after 15 minutes)
StorageMore than 1,000 MB of stored logs blocks adding or editing trace flags until logs are deleted
Trace windowExpirationDate less than 24 hours after StartDate

UNVERIFIED (2026-10-03): a per-user cap on the number of stored logs; version 1.0.0 of this skill said 20, and the 262 Apex guide does not state one.

Reading a log

The header lists the API version and category levels. EXECUTION_STARTED and EXECUTION_FINISHED delimit a transaction; CODE_UNIT_STARTED and CODE_UNIT_FINISHED delimit triggers, validation rules, future calls, batch start, execute, and finish, scheduled execute, and anonymous blocks. Each line is timestamp (nanoseconds since request start)|EVENT|details. USER_DEBUG carries System.debug output, DML_BEGIN shows Op, Type, and Rows, and CUMULATIVE_LIMIT_USAGE with LIMIT_USAGE_FOR_NS shows limit consumption. Session IDs appear as SESSION_ID_REMOVED.

Anonymous Apex

Anonymous blocks need "API Enabled" and "Author Apex" (execution through the API allows restricted access without Author Apex). They run as the current user, can fail to compile if the code violates the user's object or field permissions, and run with sharing. Changes commit only if the whole block succeeds. Run them from the Developer Console, VS Code, or sf apex run --file script.apex.

Apex Replay Debugger

The Replay Debugger in the Salesforce Extensions for VS Code replays a downloaded log with breakpoints and variable inspection; it cannot re-run code. UNVERIFIED (2026-10-03): the exact log levels and checkpoint counts it requires; the extension documentation page did not return its text to a fetch. Capture with high Apex Code detail on a narrow scope so the log stays under 20 MB.


Mode 1: Set Up a Debug Log

  1. Setup > Debug Logs > New, or sf apex tail log for your own user (it sets a DEVELOPER_LOG trace flag).
  2. Traced Entity Type: User for interactive work; Automated Process for platform event triggers, event processes, and resumed flows; the configured user if an event trigger's running user is overridden.
  3. Window: start now, end before the 24-hour limit; 30 minutes is usually enough.
  4. Debug level: Apex Code DEBUG, Database INFO, others NONE or INFO as needed.
  5. Optional: add a CLASS_TRACING trace flag on the one class or trigger that needs FINE or FINEST.
  6. Reproduce, then open the log in Setup, the Developer Console, or sf apex get log --number 1.

Mode 2: Read an Existing Log

Search for FATAL_ERROR, EXCEPTION_THROWN, and USER_DEBUG, then read the last LIMIT_USAGE_FOR_NS block before the failure. If lines you expect are missing in a large log, assume the 20 MB reduction removed older lines and re-capture with lower levels.

Mode 3: Troubleshoot Missing or Incomplete Logs

SymptomLikely causeFix
No log after the operationTrace flag expired or not yet startedCheck StartDate and ExpirationDate; create a new flag
Event trigger or resumed flow never logsTraced the publishing user onlyAdd an Automated Process trace flag (or the overridden user)
Class trace flag set, still no logCLASS_TRACING doesn't generate logsAdd a user or Automated Process trace flag too
Cannot add a trace flagOrg holds more than 1,000 MB of logsDelete old logs
Trace flags turned off by themselvesMore than 1,000 MB generated in 15 minutesLower levels, narrow scope, re-enable after 15 minutes
Expected lines missing in a big log20 MB reduction removed older linesLower verbosity; use class tracing for detail
Log not in Developer Console Logs tabLogs created by Automated Process aren't shown thereView in Setup > Debug Logs or with sf apex get log

  1. Identify the running entity. User, Automated Process, or an overridden trigger user; note whether a class needs extra detail.
  2. Create the debug level and trace flag. Setup, the Tooling API, or sf data create record --use-tooling-api --sobject TraceFlag (see references/code-examples.md).
  3. Reproduce inside the window and keep it under the 24-hour limit.
  4. Retrieve and read. sf apex get log, Setup, or the Developer Console; search for FATAL_ERROR and LIMIT_USAGE_FOR_NS.
  5. Clean up. Delete or let the trace flag expire, delete large logs, and lower Developer Console levels before deployments.
  6. Lint the setup. Run python3 scripts/check_debug_logs_and_developer_console.py --manifest-dir <folder> over saved trace flag JSON and anonymous Apex scripts.

Review Checklist


Package files