Friday, January 18, 2019

Debugging Salesforce Tests with VS Code

Debugging in Salesforce is relatively new and it immature compared to debugging in Visual Studio or Eclipse.  Even Microsoft Access has a better debugger than Salesforce.  Essentially logs files are created when running tests and then the log files are used to step through the code.  It is after the fact debugging, you cannot change the path that the code has gone.

If you haven't already, set up VS Code for Salesforce


  1. Click the Debug icon
  2. In the drop down list at the top under Debug, Add Configuration.  Select Apex Replay Debugger
  3. Make sure that you have pulled all your code and tests down from source control or from your org.
  4. Using Ctrl-Shift-P on Windows or Command-Shift-P on a Mac, select SFDX: Turn On Apex Debug Log for Replay Debugger
  5. Set a break point in your test
  6. Run your test by clicking Run Test above the test method name in VS Code 
  7. Using Ctrl-Shift-P on Windows or Command-Shift-P on a Mac, select SFDX: Turn Off Apex Debug Log for Replay Debugger
  8. Using Ctrl-Shift-P on Windows or Command-Shift-P on a Mac, select SFDX: Get Apex Debug Logs
  9. Click the Debug icon
  10. Click the Launch Apex Replay Debugger
  11. You can see local variables on the left and you can step into code

No comments:

Post a Comment