Skip to content
| Marketplace
Sign in
Visual Studio Code>Debuggers>Salesforce Apex DebugNew to Visual Studio Code? Get it now.

Salesforce Apex Debug

Charlie Jonas

|
32,659 installs
| (0) | Free
Open Source extension for Salesforce debugging
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

Apex Debug (Beta)

Build Status Visual Studio Marketplace

A Visual Studio Code debugger for the Salesforce Apex language.

'Log Reply' Debugging simulates Apex debugging by reading a log file and reconstructing stack frames.

Supports step, step-into, step-return, continue and breakpoints but it is not connected to any real debugger.

Getting Started

Configuring Apex Debug

  • Install Mavensmate Extension (required dependency)
  • Install the Apex Debug extension in VS Code.
  • Create/Open a Mavensmate project
  • Check that config/.local_store has been populated
  • add new launch.json by going to the Debug view, clicking the 'gear' icon and selecting Apex-Debug
    • workspaceRoot must point to the root of a mavensmate project
    • You can set logFile to a hardcoded value, if desired. ${command.AskForLogName} will allow you to select files from debug\logs\

Example launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Apex-Debug",
            "type": "apex",
            "request": "launch",
            "logFile": "${command.AskForLogName}",
            "workspaceRoot": "${workspaceRoot}",
            "stopOnEntry": true,
            "traceLog": false //output log lines as they are processed
        }
    ]
}

Running Debugger

  • Set log levels in /config/.debug to "ApexCode": "FINEST", "System": "FINE" & "Visualforce": "FINE" (now required to debug VF pages!).
  • run Mavensmate: Start logging from command pallet
    • NOTE: There is a known issue with mavensmate where logs are not downloaded when using API v37 and above. Set API version to 36 in Mavenmsate: Global Settings in order to stream logs.
  • Trigger a log event (Run Anyonmous Apex, load a page, etc). File should show up in debug/logs.
  • Switch into Debug View
  • Press the green 'play' button
  • Select a file (if not hardcoded in launch.json)

Usage Notes

  • If your classes change from the time you generated the log, things will certainly break
  • If your log gets too long, Salesforce will truncate it. Try reducing non-required levels (use NONE).
  • Depending on the execution type, some lines might never be stepped on, dispite the fact they were actually executed. Don't rely on the fact that a breakpoint wasn't hit to indicate that the line was not executed
  • This will probably never be perfect (although it can be much better than it currently is). Salesforce only gives us so much info to work with.

Supported Opporations

  • Set Breakpoint
  • Next
  • Step into
  • Step out
  • Continue
  • Hit Condition Breakpoints (< 5, >= 10, etc)
  • Variable Inspection (beta)

[TODO]

  • Remove depedancy on mavensmate
  • Conditional Breakpoints
  • Break on exception
  • Add/Improve support for all execution types (tests, batch, etc)
  • Improve stack variable display
  • Get rid of redudant/bad steps

Contributing

Please Do!

Debugging the Debugger

  • Fork
  • Clone
  • Open in VS code
  • Open src/apexDebug.ts. Set a break point at start of launchRequest()
  • Open Debug Window, select Run Server configuration
  • F5 (starts debugging)
  • Setup/Open a mavensmate project (See getting started)
  • Open launch.json and add "debugServer": 4711, above configurations
  • F5
  • Your vs-apex-debugger project should stop on breakpoint

Developer Resources

  • VS Code Gitter: Gitter Chat
  • Debug Adapter tutorial
  • Mock Debug Sample (used as scaffolding for this project)
  • Contact us
  • Jobs
  • Privacy
  • Terms of use
  • Trademarks
© 2023 Microsoft