Create Projects
Quick Start with Apex Development
Apex Tools
Use Anonymous Apex
Test Apex Code
Refactor Apex Code
Apex Replay Debugger
Apex Interactive Debugger
Apex ISV Debugger
Aura
Visualforce
Use Custom Code Templates
Apex Interactive Debugger, also called the Apex Debugger, is a traditional debugger that allows customers to debug their Apex code in sandboxes and scratch orgs, in real time, using VS Code as the client. You can use it to:
To debug subscribers’ sandbox orgs, use the ISV Customer Debugger, which is part of the Apex Interactive Debugger extension.
The first time that you use Apex Debugger in VS Code, complete these setup steps.
Note: You can use the default license provided to License Management orgs only with the ISV Customer Debugger to debug subscriber orgs. If you don’t have an Apex Debugger license, use the Replay Debugger.
DebugApex feature to the scratch org definition files for all the types of scratch orgs that you plan to debug:"features": "DebugApex"DebugApex feature.Permission Sets in the Quick Find box, then select Permission Sets.Debug Apex.sfdx force:user:permset:assign -n Your_Perm_Set_Name.launch.json file, click the gear icon (hover text: Configure or Fix launch.json) and then select Apex Debugger. (If you’ve already created this file, clicking the gear icon opens the file.)"configurations" array, add a "Launch Apex Debugger" configuration. The minimum information it should contain:
1"configurations": [
2 {
3 "name": "Launch Apex Debugger",
4 "type": "apex",
5 "request": "launch",
6 "sfdxProject": "${workspaceRoot}"
7 }
8]launch.json file. Each project needs only one launch.json file, even if you work with multiple scratch orgs. This file lives in the project’s .vscode directory.An unofficial debugger extension called Salesforce Apex Debug is available in the Visual Studio Marketplace. It conflicts with our official extension. Make sure you disable that extension while using ours.
Note
To set a line breakpoint, open a .cls or .trigger file and click the column to the left of the line numbers. Active breakpoints are red. Inactive breakpoints are gray. You can see a list of your breakpoints in the Breakpoints panel of the Debug view.
To start a debugging session, from the configuration dropdown menu at the top of the Debug view, select Launch Apex Debugger. Then, click the green play icon (hover text: Start Debugging).
While a debugging session is in progress, any synchronous activity that runs a line of code with a breakpoint causes execution to halt at the breakpoint. While execution is paused, you can inspect the call stack and see the current values of your variables. You can also step through your code, using the Debug actions pane that appears at the top of the editor while a debugging session is in progress, and watch those values change. You can debug up to two threads at a time. For more information, see Debugging in the Visual Studio Code docs.
To make Apex Debugger halt execution when an exception is thrown during a debugging session, set breakpoints on exceptions. When an exception breakpoint is hit, the debugger pauses on the line of code that caused the exception. The Call Stack panel in the Debug view shows the name of the exception.
To set an exception breakpoint, press Ctrl+Shift+P (Windows or Linux) or Cmd+Shift+P (macOS) to open the Command Palette, then select SFDX: Configure Apex Debug Exceptions. The list of available exceptions includes the exceptions in the System namespace and the Apex classes in your project that extend Exception. Select an exception from the list, and then select Always break.
To see your exception breakpoints, run SFDX: Configure Apex Debug Exceptions. The top of the list shows the exception classes that have active breakpoints, labeled Always break. To remove an exception breakpoint, select an exception from the list and then select Never break.
When you close VS Code, all your exception breakpoints are removed. (Your line breakpoints, however, remain.)
To filter which requests are debugged, edit your launch.json file to set up an allowed users list. (The launch.json file lives in your project’s .vscode directory.) If you don’t use an allowed users list, all events in your org trigger debugging during a debugging session. Set up allowlist users or request types to focus only on the events that are relevant to the problem you’re debugging.
Add filters to the "Launch Apex Debugger" configuration:
1"configurations": [
2 {
3 "name": "Launch Apex Debugger",
4 "type": "apex",
5 "request": "launch",
6 "sfdxProject": "${workspaceRoot}",
7 "userIdFilter": [],
8 "requestTypeFilter": [],
9 "entryPointFilter": ""
10 }
11]To auto-complete potential request type values for "requestTypeFilter", press Ctrl+Space.
To filter by entry point, enter a regular expression as the value for "entryPointFilter". For example, to allow requests made by the Visualforce page MyPage, enter ".*/apex/MyPage.apexp".
Keep these limitations and known issues in mind when working with Apex Debugger.
If you edit Apex classes while a debugging session is in progress, your breakpoints might not match your debugging output after you save your changes.
Your debugging session is orphaned when you close VS Code before stopping your session. If you have an orphaned session, you can’t start a new session. To stop your active session, in VS Code, run SFDX: Stop Apex Debugger Session. To manage your Dev Hub’s Apex Debugger sessions, go to Apex Debugger in Setup.
Eval functionality isn’t available.
Hot swapping isn’t permitted. These actions kill your debugging session:
You can’t save changes to these items during a debugging session:
These entry points aren’t supported:
Tip: Code that’s between a pair of
startTestandstopTestmethods can run synchronously. To debug your asynchronous functionality, use these methods within your tests.
@future annotationget or set method must be within the method’s body.toString methods.[SELECT Id, ContactId, Contact.accountId, Contact.Account.ownerId FROM Case], your results are nested as follows.
1Case
2--> Contact
3-----> contactId
4-----> Account
5--------> accountId
6--------> ownerIddurableId even if you don’t explicitly SELECT that variable.