force:apex:execute hangs for 60s and returns status 0 when it fails
See original GitHub issueSummary
When you run force:apex:execute
and enter the Apex code in STDIN, the CLI hangs for 60 seconds even though the request is already completed and the result is present in STDOUT
And if the entered Apex code does not compile or throws an Exception, the CLI returns status 0
Steps To Reproduce:
Valid Apex code (hangs for 60s):
sfdx force:apex:execute -u dev22483 <<< "System.debug('hello forcedotcom/cli!');"
Invalid Apex code (hangs for 60s and returns 0):
sfdx force:apex:execute -u dev22483 <<< "invalid apex code"
Apex code that throws exception (hangs for 60s and returns 0):
sfdx force:apex:execute -u dev22483 <<< "throw new IllegalArgumentException();"
It even returns 0 if a governor limit is reached:
sfdx force:apex:execute -u dev22483 <<< "for (Integer i = 0; i < 101; i++) Object queryResult = [SELECT Id FROM Product2 LIMIT 1];"
Expected result
- The CLI should return the result as soon as the anonymous apex code block is executed
- The CLI should not return status 0 if the anonymous apex code block does not compile
- The CLI should not return status 0 if the anonymous apex code block throws an exception
- The CLI should not return status 0 if the anonymous apex code block throws an uncatchable exception (governor limit reached)
Actual result
The CLI is always hanging for 60s even though the execution was completed and is always returning status 0 for compile errors and exceptions.
Additional information
Extra:
If using the --json
flag, although the command still hangs for 60s and returns 0, I can see that the json result contains the success
and compiled
fields, so with jq we can override the CLI behavior and return non-zero until this is resolved:

SFDX CLI Version:
sfdx-cli/7.89.2 darwin-x64 node-v15.5.1
SFDX plugin Versions:
@oclif/plugin-autocomplete 0.3.0 (core)
@oclif/plugin-commands 1.3.0 (core)
@oclif/plugin-help 3.2.2 (core)
@oclif/plugin-not-found 1.2.4 (core)
@oclif/plugin-plugins 1.10.0 (core)
@oclif/plugin-update 1.4.0-2 (core)
@oclif/plugin-warn-if-update-available 1.7.0 (core)
@oclif/plugin-which 1.0.3 (core)
@salesforce/sfdx-diff 0.0.6
@salesforce/sfdx-trust 3.6.0 (core)
alias 1.1.7 (core)
auth 1.4.10
config 1.2.5 (core)
evergreen 0.34.0
└─ evergreen-build 0.20.2
generator 1.1.5 (core)
salesforcedx 51.1.1 (core)
├─ limits 1.0.4 (core)
├─ user 1.1.2 (core)
├─ custom-metadata 1.0.11 (core)
├─ schema 1.0.4 (core)
├─ templates 51.3.0 (core)
├─ apex 0.1.4 (core)
├─ @salesforce/sfdx-plugin-lwc-test 0.1.7 (core)
└─ salesforce-alm 51.1.1 (core)
sfdmu 3.10.0
sfdx-cli 7.89.2 (core)
telemetry 1.1.1 (core)
OS and version: macOS Catalina 10.15.7
Issue Analytics
- State:
- Created 3 years ago
- Comments:6
@mshanemc just to clarify: is this really an apex issue? 🤔 Pardon my ignorance because I also don’t know if the CLI code is owned by multiple teams or not, but from what I could see from this issue the code already compiled, executed and the result was returned and presented in stdout, but the CLI is still hanged after that.
The problem apparently relies in the CLI itself and not in Apex or an API, The CLI always hangs for exactly 60 seconds, even though the API request was processed and the result returned.
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.