+ Start a Discussion

sfdx force:data:soql:query returns not recognized internal or external command error

If you try to run an sfdx soql query on a Windows terminal, PS, CMD, etc, you will get the following error if your profile contans spaces in the path:
PS C:\sfdx\project1> sfdx force:data:soql:query --query "select count() from Contact"
'C:\Users\Luis' is not recognized as an internal or external command,
operable program or batch file.
To work around this, set your LOCALAPPDATA environment variable to the eight character equivalent of the path segment that contains the spaces. For example, in my case, I set LOCALAPPDATA to C:\Users\LUISLU~1\AppData\Local:
PS C:\sfdx\project1>$Env:LOCALAPPDATA = "C:\Users\LUISLU~1\AppData\Local"
PS C:\sfdx\project1> sfdx force:data:soql:query --query "select Name from Project__c"
Project 1
Total number of records retrieved: 1.
I have used other sfdx commands without problems, but apparently, force:data:soql:query uses the LOCALAPPDATA environment variable when executing the command.
Josip KrajnovićJosip Krajnović
This worked for me:

It would seem that SFDX does not handle spaces in the LOCALAPPDATA environment variable.

The workaround is to use short names. In a command line, execute:

This command line is then ready for SFDX use.

Note : in a batch file, do not forget to double the % sign.