# Diagnosing Apex with debug logs and Replay Debugger

*Platform Developer II Study Guide · Testing, Debugging, and Deployment · Last updated October 16, 2026 · https://www.certifyforce.com/study-guide/platform-developer-ii/testing-debugging-and-deployment/diagnosing-apex-with-debug-logs-and-replay-debugger*

Trace the right entity (user, Automated Process, class or trigger), tune log levels to beat the 20 MB truncation, read the Log Inspector and Limits output, replay logs with checkpoints, and decode DmlException rows, exception emails, AsyncApexJob errors and test-only failures.

- Certification: Salesforce Platform Developer II
- Exam section: Testing, Debugging, and Deployment
- Study guide: https://www.certifyforce.com/study-guide/platform-developer-ii

**Official exam objective:**

> Given a scenario, Apex code, Apex trigger, or Apex tests that's not executing as expected, apply techniques tools to identify the cause.

## What the exam expects

- Choose the trace flag that captures the failing transaction: a user (including an integration user), Automated Process for event subscribers, or a class or trigger override.
- Predict what a log contains from its debug levels, and fix logs that are truncated or too noisy.
- Locate slow code and limit consumption with the Log Inspector and the `Limits` methods; inspect trigger context with Replay Debugger checkpoints.
- Identify failing rows and jobs with `DmlException` methods, exception emails, `AsyncApexJob` and `sf apex tail log`.
- Explain test-only and trigger-skipping failures: Owner relationships in data-silo tests, the standard price book, cascade deletes and mixed DML.

Key terms: **trace flag** (an entity, time window and debug level that turns on logging); **debug level** (a log level per category such as Apex Code or Database); **CLASS_TRACING** (a class or trigger trace flag that overrides levels but never creates logs); **checkpoint** (a line where Replay Debugger captures a heap dump).

This unit assumes the Platform Developer guide's *Debugging with logs and monitoring async jobs and flows* (trace flag basics, reading a log, Developer Console).

## Key facts

| Fact | Detail | Source |
|---|---|---|
| CLASS_TRACING | Overrides levels; never generates logs on its own | [Debug Log Levels](https://help.salesforce.com/s/articleView?id=platform.code_setting_debug_log_levels.htm&type=5) |
| Class flag inheritance | Called methods and triggers inherit the override unless they have their own | [Debug Log Filtering for Apex Classes and Apex Triggers](https://help.salesforce.com/s/articleView?id=sf.code_debug_log_classes.htm&type=5) |
| Event trigger logs | Created by Automated Process (or the overriding running user); not in the Developer Console Logs tab | [Set Up Debug Logs for Event Subscriptions](https://developer.salesforce.com/docs/atlas.en-us.platform_events.meta/platform_events/platform_events_subscribe_debug.htm) |
| `System.debug` default level | DEBUG, unless a `LoggingLevel` is passed | [Debug Log Levels](https://help.salesforce.com/s/articleView?id=platform.code_setting_debug_log_levels.htm&type=5) |
| Log size | 20 MB per log; older lines removed above it | [Debug Log](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_debugging_debug_log.htm) |
| Log volume | More than 1,000 MB in 15 minutes disables trace flags | [Debug Log](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_debugging_debug_log.htm) |
| Checkpoints | Up to five; expire after 30 minutes; only place trigger context variables show | [Apex Replay Debugger](https://developer.salesforce.com/docs/platform/sfvscode-extensions/guide/replay-debugger.html) |
| Time per process | Timeline tab: milliseconds and percent of the request | [Log Inspector](https://help.salesforce.com/s/articleView?id=platform.code_dev_console_view_system_log.htm&type=5) |
| Failed batch details | `AsyncApexJob.NumberOfErrors` and `ExtendedStatus` | [AsyncApexJob](https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_asyncapexjob.htm) |
| Live logs in terminal | `sf apex tail log` | [apex Commands](https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_apex_commands_unified.htm) |

## Check yourself

- Why does a CLASS_TRACING flag on its own produce no log?
- When must Replay Debugger checkpoints be uploaded?
- Why can a 20 MB log miss `System.debug` output from early in the transaction?
- Which `DmlException` method returns a failed row's position in the original list?
- Which Log Inspector views show where a slow save spent its time?

## Sources

- [Debug Log](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_debugging_debug_log.htm)
- [Debug Log Levels](https://help.salesforce.com/s/articleView?id=platform.code_setting_debug_log_levels.htm&type=5)
- [Set Up Debug Logging](https://help.salesforce.com/s/articleView?id=sf.code_add_users_debug_log.htm&type=5)
- [Debug Log Filtering for Apex Classes and Apex Triggers](https://help.salesforce.com/s/articleView?id=sf.code_debug_log_classes.htm&type=5)
- [Set Up Debug Logs for Event Subscriptions](https://developer.salesforce.com/docs/atlas.en-us.platform_events.meta/platform_events/platform_events_subscribe_debug.htm)
- [Add a Trace Flag Entry for the Automated Process User](https://developer.salesforce.com/docs/atlas.en-us.platform_events.meta/platform_events/platform_events_subscribe_debug_autoproc.htm)
- [Log Inspector](https://help.salesforce.com/s/articleView?id=platform.code_dev_console_view_system_log.htm&type=5)
- [Using Limits, startTest, and stopTest](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_tools_start_stop_test.htm)
- [Apex Replay Debugger](https://developer.salesforce.com/docs/platform/sfvscode-extensions/guide/replay-debugger.html)
- [Exception Class and Built-In Exceptions](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_classes_exception_methods.htm)
- [What Happens When an Apex Exception Occurs?](https://help.salesforce.com/s/articleView?id=platform.code_apex_exceptions.htm&type=5)
- [AsyncApexJob](https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_asyncapexjob.htm)
- [apex Commands](https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_apex_commands_unified.htm)
- [Isolation of Test Data from Organization Data](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_data_access.htm)
- [Test Class](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_test.htm)
- [Operations That Don't Invoke Triggers](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_ignoring_operations.htm)
- [Mixed DML Operations in Test Methods](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_dml_non_mix_sobjects_test_methods.htm)

## About the full unit

The "Core concepts", "Exam traps" and "Worked scenario" sections of this unit, its 16 linked practice questions, and unlimited timed mock exams are included with the Platform Developer II pack (USD $19): https://www.certifyforce.com/practice-exams
