Skip to main content
Join the Agentforce Hackathon on Nov. 18-19 to compete for a $20,000 Grand Prize. Sign up now. Terms apply.

Launch Your Trailhead Playground

Learning Objectives

In this project, you’ll:

  • Set breakpoints and checkpoints to step through code and inspect variable values at specific line numbers in a debug session.
  • Invoke Apex tests and download debug logs using Visual Studio Code.
  • Find and fix a bug using Apex Replay Debugger for Visual Studio Code.

Introduction

“Any bug not detected in the design phase will cost ten times more time to detect at the coding phase and an additional ten times more at the debugging phase.” —Dr. Nikolai Bezroukov, The Art of Debugging

Searching for software bugs represented by a magnifying glass over a ladybug

Debugging and testing are related but distinct processes in software development. Testing attempts to find and report errors. Debugging attempts to identify the cause of those errors and fix them. And according to Dr. Nikolai Bezroukov, when finding and squashing bugs in your code, the earlier the better.

Apex provides testing support through a full framework for isolated execution of Apex tests, including nonproduction orgs such as sandboxes and scratch orgs. Apex also provides debugging support through the System.debug statement, debug logs, and debuggers.

When trace flags are enabled, your Apex code generates debug logs, which are recordings of all interactions in a transaction. Apex Replay Debugger simulates a live debugging session using a debug log. It presents the logged information, including variable values, call stack, and breakpoints, similarly to an interactive debugger, so you can debug your Apex code.

What Is Apex Replay Debugger?

Apex Replay Debugger is a free tool that allows you to debug your Apex code by inspecting debug logs using Visual Studio Code as the client. Running the replay debugger gives you the same features you expect from other debuggers. You can view variables, set breakpoints, and hover over variables to see their current value. You no longer need to parse through thousands of log lines manually or sprinkle your code with System.debug statements to see variable values or track the code execution path.

Apex Replay Debugger also makes it easy to work asynchronously and collaborate with others to solve problems. Because you can launch a replay debugger session from any replay-enabled debug log, clients and coworkers can share debug logs to help solve problems. To start a debugging session, open a debug log in Visual Studio Code and right-click any line in the file to launch the debugger.

Launching Apex Replay Debugger from a debug log opened in Visual Studio Code

The debugging process involves iterating through several steps. Edit your Apex code, deploy the code to your org, reproduce the buggy scenario, download the resulting debug log, then launch Apex Replay Debugger with that debug log.

Note

A replay-enabled debug log includes statements generated with a log level of FINER or FINEST for log category Visualforce and a log level of FINEST for log category Apex Code. Learn more about log levels and log categories in the Debug Log Levels documentation.

What Is Apex Interactive Debugger?

Apex Interactive Debugger, also included in the Salesforce Extension Pack, allows customers to debug their Apex code on sandboxes and scratch orgs, in real time, using Visual Studio Code as the client.

Apex Interactive Debugger also comes with features for independent software vendor (ISV) partners working with subscribers who install a managed package. Because of the protections against seeing managed code, subscribers can’t debug ISV code in their orgs. With ISV Customer Debugger, an ISV can work with a subscriber to debug issues specific to the subscriber’s org.

For pricing details for Apex Interactive Debugger or ISV Customer Debugger, contact your Salesforce account executive.

This project focuses on how to set up and use the free Apex Replay Debugger.

Create Your Trailhead Playground

For this project, create a new Trailhead Playground. Scroll to the bottom of this page, click the down arrow next to Launch, and select Create a Trailhead Playground.

Resources

Salesforce 도움말에서 Trailhead 피드백을 공유하세요.

Trailhead에 관한 여러분의 의견에 귀 기울이겠습니다. 이제 Salesforce 도움말 사이트에서 언제든지 새로운 피드백 양식을 작성할 수 있습니다.

자세히 알아보기 의견 공유하기