1

I have been trying to use Visual Studio code over the Developer Console because I understand that this will be the new standard for Salesforce however I find myself using the Developer Console with Visual Studio Code. The reason I use the DC with the VS Code is because while I am writing the code for the business processes I heavily use the Logs in DC with System Debug statements. My question is can VS Code also show the Logs like the DC? I get that you can create test classes and run it that way but I find using this is rather challenging when programming.

2

You can actually stream the debug log into your local computer with VSCode + Salesforce CLI tool.

Assuming you have the Salesforce CLI tool installed. To see debug log without leaving your VSCode, run this command in the terminal tab:

$ sfdx force:apex:log:tail -c | grep '|USER_DEBUG|'

Then, try create a new file within VSCode, type in below

System.debug('Hey!');

and run SFDX: Execute Anonymous Apex with Editor Contents. You'll see the log is streamed to your console.

Check out the documentation.

| improve this answer | |
  • awesome thank you. I looked for this before but all i found was you needed to create a test class first. – CodeMonger Jun 24 at 15:05
  • In order to stop the debugger do you Kill the terminal? – CodeMonger Jun 24 at 15:13
  • 1
    From the doc: by default it tails for 30 mins. But you can exit manually: Ctrl + C (Win) – Hengky Ilawan Jun 24 at 15:19
1

You can retrieve recent logs with the SFDX: Get Apex Debug Logs... command from the Command Palette, and from there, you can use the Interactive Debugger commands on the log to step through your logic as if it were running in real-time. Many of the commands are not exposed through menu clicks, so using the Command Palette is the preferred way to get at all the available commands.

| improve this answer | |
0

As a slightly different answer that does require more setup: there's a good trailhead about debugging your code in VS with checkpoints and the Apex Debugger which presents the ApexDebuggerEvent information through the Streaming API.

I've taken the below information from the trailhead and developer documentation.

First step, you need to create a permission set and assign it to your user record to give system permission "Debug Apex". Once that's assigned to your user, you can set up Apex Debugger:


Click on bug icon on left side bar

enter image description here

  1. Select create a launch.json file.
  2. Select "Apex Debugger"
  3. This should open a launch.json file that contains at least the following (should auto-populate):
"configurations": [
  {
    "name": "Launch Apex Debugger",
    "type": "apex",
    "request": "launch",
    "sfdxProject": "${workspaceRoot}"
  }
]
  1. Save this file

Now, you can "launch apex debugger" by clicking on that same icon on the left sidebar.

enter image description here

It'll be actively streaming for information and the information will appear in the "Debug console" in the lower half next to "terminal". You can set checkpoints in your code to assist further.

enter image description here

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.