Repository navigation
Error when running sf apex get test: Cannot read properties of null (reading 'Id') #3389
Copy link
Copy link
Closed
Labels
bugIssue or pull request that identifies or fixes a bugIssue or pull request that identifies or fixes a bugvalidatedVersion information for this issue has been validatedVersion information for this issue has been validated
Description
Summary
When running the sf apex get test -i xxxxxx -c --json I run into the following error:
{
"name": "TypeError",
"message": "Cannot read properties of null (reading 'Id')",
"exitCode": 10,
"context": "Test",
"stack": "TypeError: Cannot read properties of null (reading 'Id')\n at SfCommandError.from (file:///C:/Users/w511761/AppData/Local/sf/client/2.104.6-03675e8/node_modules/@salesforce/sf-plugins-core/lib/SfCommandError.js:39:16)\n at Test.catch (file:///C:/Users/w511761/AppData/Local/sf/client/2.104.6-03675e8/node_modules/@salesforce/sf-plugins-core/lib/sfCommand.js:323:47)\n at Test._run (C:\\Users\\w511761\\AppData\\Local\\sf\\client\\2.104.6-03675e8\\node_modules\\@oclif\\core\\lib\\command.js:185:29)\n at process.processTicksAndRejections (node:internal/process/task_queues:105:5)\n at async Config.runCommand (C:\\Users\\w511761\\AppData\\Local\\sf\\client\\2.104.6-03675e8\\node_modules\\@oclif\\core\\lib\\config\\config.js:456:25)\n at async run (C:\\Users\\w511761\\AppData\\Local\\sf\\client\\2.104.6-03675e8\\node_modules\\@oclif\\core\\lib\\main.js:97:16)\n at async file:///C:/Users/w511761/AppData/Local/sf/client/2.104.6-03675e8/bin/run.js:15:1",
"cause": "TypeError: Cannot read properties of null (reading 'Id')\n at C:\\Users\\w511761\\AppData\\Local\\sf\\client\\2.104.6-03675e8\\node_modules\\@salesforce\\apex-node\\lib\\src\\tests\\asyncTests.js:447:59\n at Array.forEach (<anonymous>)\n at AsyncTests.buildAsyncTestResults (C:\\Users\\w511761\\AppData\\Local\\sf\\client\\2.104.6-03675e8\\node_modules\\@salesforce\\apex-node\\lib\\src\\tests\\asyncTests.js:434:32)\n at descriptor.value (C:\\Users\\w511761\\AppData\\Local\\sf\\client\\2.104.6-03675e8\\node_modules\\@salesforce\\apex-node\\lib\\src\\utils\\elapsedTime.js:57:48)\n at AsyncTests.formatAsyncResults (C:\\Users\\w511761\\AppData\\Local\\sf\\client\\2.104.6-03675e8\\node_modules\\@salesforce\\apex-node\\lib\\src\\tests\\asyncTests.js:314:81)\n at process.processTicksAndRejections (node:internal/process/task_queues:105:5)\n at async AsyncTests.reportAsyncResults (C:\\Users\\w511761\\AppData\\Local\\sf\\client\\2.104.6-03675e8\\node_modules\\@salesforce\\apex-node\\lib\\src\\tests\\asyncTests.js:233:38)\n at async TestService.reportAsyncResults (C:\\Users\\w511761\\AppData\\Local\\sf\\client\\2.104.6-03675e8\\node_modules\\@salesforce\\apex-node\\lib\\src\\tests\\testService.js:173:20)\n at async Test.run (file:///C:/Users/w511761/AppData/Local/sf/client/2.104.6-03675e8/node_modules/@salesforce/plugin-apex/lib/commands/apex/get/test.js:53:24)\n at async Test._run (C:\\Users\\w511761\\AppData\\Local\\sf\\client\\2.104.6-03675e8\\node_modules\\@oclif\\core\\lib\\command.js:181:22)",
"warnings": [],
"code": "10",
"status": 10,
"commandName": "Test"
}
This is happening both in the docker image used in a Github action (salesforce/cli:latest-full) and locally.
Steps To Reproduce
- Have any valid sfdx project open with the latest cli version
- Run the command
sf apex run test -c --jsonand save the test run id provided - After the apex tests finished running, execute the command
sf apex get test -i xxxxxx -c --jsonwith the id from the previous step.
Expected result
The command should return a json with the apex tests results for the test id provided.
Actual result
The json returned shows the error message: TypeError: Cannot read properties of null (reading 'Id')
Additional information
This issue started happening on September 8th 2025
System Information
{
"architecture": "win32-x64",
"cliVersion": "@salesforce/cli/2.104.6",
"nodeVersion": "node-v22.18.0",
"osVersion": "Windows_NT 10.0.22631",
"rootPath": "C:\\Users\\w511761\\AppData\\Local\\sf\\client\\2.104.6-03675e8",
"shell": "powershell",
"pluginVersions": [
"@oclif/plugin-autocomplete 3.2.34 (core)",
"@oclif/plugin-commands 4.1.32 (core)",
"@oclif/plugin-help 6.2.32 (core)",
"@oclif/plugin-not-found 3.2.66 (core)",
"@oclif/plugin-plugins 5.4.46 (core)",
"@oclif/plugin-search 1.2.28 (core)",
"@oclif/plugin-update 4.7.4 (core)",
"@oclif/plugin-version 2.2.32 (core)",
"@oclif/plugin-warn-if-update-available 3.1.46 (core)",
"@oclif/plugin-which 3.2.39 (core)",
"@salesforce/cli 2.104.6 (core)",
"agent 1.24.6 (core)",
"apex 3.6.19 (core)",
"api 1.3.3 (core)",
"auth 3.9.0 (core)",
"data 4.0.55 (core)",
"deploy-retrieve 3.23.0 (core)",
"info 3.4.83 (core)",
"limits 3.3.65 (core)",
"marketplace 1.3.8 (core)",
"org 5.9.25 (core)",
"packaging 2.19.7 (core)",
"schema 3.3.79 (core)",
"settings 2.4.44 (core)",
"sobject 1.4.69 (core)",
"telemetry 3.6.55 (core)",
"templates 56.3.61 (core)",
"trust 3.7.113 (core)",
"user 3.6.35 (core)",
"@salesforce/sfdx-scanner 4.12.0 (user) published 132 days ago (Tue Apr 29 2025)"
]
}
Reacted by DainiusSenf and Trevor Smart
Metadata
Metadata
Assignees
Labels
bugIssue or pull request that identifies or fixes a bugIssue or pull request that identifies or fixes a bugvalidatedVersion information for this issue has been validatedVersion information for this issue has been validated
Activity
github-actions commentedon Sep 9, 2025
Thank you for filing this issue. We appreciate your feedback and will review the issue as soon as possible. Remember, however, that GitHub isn't a mechanism for receiving support under any agreement or SLA. If you require immediate assistance, contact Salesforce Customer Support.
DainiusSenf commentedon Sep 11, 2025
Same issue. I noticed it happens on sandboxes with new SF version v65.0. Works fine on v64.0.
cvoge commentedon Sep 12, 2025
Hello,
We are receiving a similar error when running:
sf apex run test --test-level RunLocalTests --code-coverage --synchronous --result-format json ....
git2gus commentedon Sep 12, 2025
This issue has been linked to a new work item: W-19627226
cristiand391 commentedon Sep 12, 2025
I'm able to repro this on v65.0, works fine on v64.0.
A teammate pointed out there are some API changes in v65.0 in the endpoints used for this functionality, some workarounds:
--api-version 64.0when starting the test run (doesn't work if you are retrieving results, the operation should start on 64.0).We'll need to update the CLI commands to handle the new changes. Thanks for reporting!
LyonsTechLLC commentedon Sep 12, 2025
Facing the same issue everyone else is having.
cristiand391 commentedon Sep 15, 2025
update:
this may have been fixed in the nightly channle (sf v2.107.4), could someone give it a try and confirm?:
see:
https://developer.salesforce.com/docs/atlas.en-us.sfdx_setup.meta/sfdx_setup/sfdx_setup_install_cli_rc.htm
richardiago commentedon Sep 15, 2025
@cristiand391 It worked in the nightly channel (sf v2.107.4)
skrel commentedon Sep 15, 2025
Same issue here
AdamOfHyrule commentedon Sep 24, 2025
Just wanted to let people know that I was also facing this issue since the Winter26 preview and I fixed it by removing a Flow Test which is now being run during local test execution.
I noticed the flow test pop up in the Application Test Execution window when running local tests
sf apex run test -l RunLocalTestand tried deleting it from the inactive flow itself - it solved the problem for me and now I am able to usesf apex get test -i ...Hopefully in the future the CLI command will be able to exclude flow tests or even better, produce results even if Flow Tests are included in application test execution.
richardiago commentedon Sep 29, 2025
This issue has been fixed since the last release. Thank you guys!
DmitriyBereza commentedon Oct 24, 2025
Hi all!
Today I faced the same issue, both on @salesforce/cli/2.104.6 and 2.109.6, class api version 65
My investigation:
Sybcronious commands such as: sf apex run test --class-names %ClassName% --synchronous --result-format json --code-coverage
works well, however async is failing:
sf apex run test --class-names %ClassName% --result-format json --code-coverage --wait 60
or this:
sf apex run test --class-names %ClassName% --result-format json --code-coverage --wait 0(runs well)
sf apex get test --test-run-id <RUN_ID> --result-format json --code-coverage(fails).
I downgrade version to 64, didn't help.
UPD: My test was too simple(I needed to write an evergreen test, so it was basically System.assert(true)) and didn't provide any coverage. So the coverage filed was null and that's why CLI returned NPE.