Apex Replay Debugger

Apex Replay Debugger - Salesforce Developer Guide

In this blog, we are going to discuss the apex replay debugger. Before starting the discussion about apex replay debugger let’s learn some basic knowledge about debugging like the importance of debugging or how to do it or how it works. Sometimes we are a little bit confused about the testing and debugging. We think they are the same but in the testing, we’re going to detect and report the errors and in debugging first we figure out the cause of the error then fix those errors.

We know that apex gives us debugging support such as debug logs, system.debug statements, and debuggers. If we talk about the Apex replay debugger then it provides you the same features you want from the other debugger tools. By using the debug logs, apex replay debugger replicates a live debugging period and in this debugging period, we get all the information like variables value breakpoints and call stack. Apex replay debugger is a free tool that grants you to debug your apex code in visual studio code.

Advertisement

Let’s start the discussion of the Apex Replay Debugger. Follow the below steps to debug your apex code in the VS code.

1. First, you have to create a project in the vs code, if you are new in the vs code then follow the below steps to create a project in vs code. 

  • Open your vs code (make sure you already installed and configured Salesforce CLI and required extensions and also java is installed & add its path configured in the VS code apex settings), Enter ctrl+shift+p to open command palette.
  • Enter SFDX create a project in the command palette and Select this SFDX: Create Project with Manifest.
  • Select default or standard template → Enter your project name → Choose your folder and create a project in it.

2. Create your new Apex class or you can use your previous apex classes.

dont miss out iconDon't forget to check out: TriggerFactory in Salesforce Apex | The Developer Guide

3. Create a Launch configuration, before creating the launch configuration let’s know brief knowledge about this. Basically, it notifies the VS code how you will start the debugger session with the apex replay debugger. Follow the below steps to create a Launch configuration.

  • Go to VS code → Click on the Run and Debug tab (available in the left navigation bar or you can take reference from the below diagram)
  • Click on Setting (you can find this at top of the debug panel ) it opens the below JSON.
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
    {
        "name": "Launch Apex Replay Debugger",
        "type": "apex-replay",
        "request": "launch",
        "logFile": "${command:AskForLogFileName}",
        "stopOnEntry": true,
        "trace": true
    }
]


4. If you want to set the checkpoints in the apex follow below points:

Open Command Palette (Ctrl+shift+P) → Enter checkpoints → Select SFDX: Toggle Checkpoint.

Focus your cursor on that line, Where you want to set the checkpoints. You should see a red dot next to that line number showing that the checkpoint was set.

Open Command palette (Ctrl+shift+P) → Enter checkpoints → Select SFDX: Update Checkpoints in Org.

dont miss out iconCheck out another amazing blog by Shweta here: Successful Implementation of Omni-Channel | Salesforce Guide

5. Open Command palette (Ctrl+shift+P) → Enter Apex Replay debugger → Select SFDX: Turn On Apex Debug Log for Replay Debugger

6. After enabling replay debugger, Open Command palette (Ctrl+shift+P) → Enter SFDX get → Select SFDX: Get Apex Debug Logs → Choose your debug log and then VS code opens the download logs.

  • Click on SFDX: Launch Apex Replay Debugger with Current File

After this below image appears. You can handle your debug logs by using these buttons.

 

Responses

Popular Salesforce Blogs