salesforcedx-vscode: Apex Replay Debugger Fails to Start Debugging From "Debug Test" link in Unit Test Class.

Summary

Using the “Debug Test” link on a specific test method of a Test class fails to stat the debugging session.

Two errors are displayed:

Cannot read properties of null (reading 'Id')
Debug Test(s) failed to run

Just updated to the current version of the Apex Replay Debugger: v61.12.0

Other observations:

  • Test method in question runs correctly and passes (when not trying to debug).
  • Checkpoints vs Breakpoints seem to be displayed differently on the “Run and Debug” panel in this version. Checkpoints now display properties: Type:None, Script:“”, Iterations:1. Previously (I recall) Breakpoints and Checkpoints both showed checkbox lists. Breakpoints can still be toggled by clicking the margin, and Checkpoints still need a “SFDX: Toggle Checkpoint” command.

Steps To Reproduce:

  1. Open Salesforce project containing unit tests.
  2. Locate a test in the test class (use source below)
  3. Place cursor on a valid code line
  4. F1: SDFX: Toggle Checkpoint
  5. (Observe: red Checkpoint icon in the margin)
  6. Click the “Debug Test” link just above one of the test methods
  7. (Observe: SFDX: Update Checkpoints in Org seems to work)
  8. (Observe: Two errors)

Expected result

A debug session should have started and “broke” with the debug cursor at the Checkpoint line.

Actual result

Two errors are displayed:

Cannot read properties of null (reading 'Id')
Debug Test(s) failed to run

Additional information

Salesforce Extension Version in VS Code: v61.12.0 Salesforce CLI Version: @salesforce/cli/2.29.5 win32-x64 node-v20.11.0 OS and version: Windows 10 22H2, OS Build: 19045.4894 VS Code version: 1.93.0 Most recent version of the extensions where this was working: 59.1.2

Example Test Class

@isTest(isParallel=false)
private class ExampleTestClass 
{
    @TestSetup static void makeData()
    {
        User portalUser = new User();
        insert portalUser;				// Should throw a DMLException
    }

    @isTest static void test0DebugTest()
    {
        String testString = 'This is a string';
        System.debug(testString);
        System.assert(testString == 'This is a string', 'Expected success, but it failed');
    }
}

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 32 (11 by maintainers)

Most upvoted comments

Additionally, Checkpoints in the makeData() method are ignored. I’m certain I have debugged makeData() in a past version.

I updated the original description to include my current understanding and the example code that demonstrates the issue.

@CristiCanizales

The “Debug Test” issue (Error: Cannot read properties of null (reading ‘Id’)) seems to be caused by a runtime DMLException in the makeData method.

To reproduce, add this method to the top of your class:

    @TestSetup
    static void makeData()
    {
        User portalUser = new User();
        insert portalUser;
    }

The test class can be deployed, but should throw a DMLException (assuming your User object requires some fields).

Getting a runtime exception in makeData is a good reason to want to run debug in the first place. So exception-free makeData() does not seem like a reasonable design requirement for the replay debugger. I’m fairly sure this worked correctly in a previous version.

Additionally, if you comment out the makeData() method and throw the exception in a test method, the debugger works fine.

So the issue is related to replaying the log if there is a runtime DMLException in the makeData() method.

@CristiCanizales ,

I made the following changes:

  • Uninstalled all extensions
  • Deleted: ….vscode\extensions
  • Deleted: …\AppData\Roaming\Code
  • Installed Salesforce Extension Pack
  • Uninstalled Zulu JDK 11
  • Installed Zulu JDF 21
  • Configured Java in VSCode

All seems to be working again. Unfortunately, we did not learn how this issue started. Given that deleting, uninstalling, and installing is so easy, I’m not sure the analytical approach is cost-effective. I’ll probably start with that next time.

Thank you for your encouragement and suggestions!