Salesforce debug with VS Code

Thomas Prouvot
3 min readMar 9, 2021

Since VS Code became the preferred (mandatory ? 😊) IDE for Salesforce developers, you may have noticed some differences for debugging with Integrated Developer Console or IntelliJ IDE + Illuminated Cloud / Jetforcer plugin.

Let’s start with this dummy code which generates logs

We will go through different examples of debug in Salesforce.

1. Debug Only

You’re sad because you can’t find your favorite button when opening the logs in VS Code? 😢

Now dry your tears and download the extension which helps you to bring back your old friend!

Filter Line:

2. Stream Logs in the terminal

Yeah I know, I can hear you, having to execute “Get Apex Debug Logs…” each time you generate a log is not the most productive way to debug and I AGREE!

That’s why I was so excited when I discovered this fabulous command which helps you to print out the USER_DEBUG line directly in your VS Code terminal:

$ sfdx force:apex:log:tail — color | grep USER_DEBUG

For windows users, it will require the installation of MinGW, fortunately you’re a developer who uses git command line (really ? 😊 ) and you already installed Git for windows which comes with MinGW installation.

3. Holy Grail: Apex Replay Debugger

Execute from the command palette “Turn On Apex Debug Log for Replay Debugger”

Now execute your code (from test class or from UI) and download the generated log with “Get Apex Debug Logs…”

Right click on the file and select “Launch Apex Replay Debugger With Current File”

Now you can place your breakpoints (eventually conditional’s one ) on the code and start debugging !

--

--