Recently, I upgraded the Salesforce CLI, sf, and ran into the following error:
Error (10): Metadata API request failed: Cannot read properties of null (reading ‘split’)
If you look closely at your Salesforce projects in VS Code or via your favorite OS Explorer, you will see that there are two hidden folders.
.sf
.sfdx
These folders contains metadata, tools, apex classes, and other tools. Regardless of the OS or VS Code that you are running – the error or errors that result from an cli upgrade manifes themselfes when trying to work with existing Salesforce projects.
I removed the .sf and .sfdx hidden folders from my project. Then, ran
sf config:set target-org=myorg
I was able to work with my project without encountering any additionals errors.
Recently, I ran into this error while refreshing my Oauth Token on VS Code. I tried to re-authorize the org and it failed. I had never encounter this type of failure. Usually, clearing out the .sfdx/<username>.json file and reauthorizing the org worked. This time it was different.. The error lingered and I had no additional information to debug. My next step was to research and troubleshoot.
Did I mention that I run Linux?
I recently had applied a bunch of package updates to my linux desktop and thought that my firewall was blocking tcp traffic into port 1717. I did a quick check and that was not the case. BTW – the local nodejs server runs only while the OAUTH workflow is in progress. Once the flow completes, the local server is shutdown.
Salesforce provides many secure flows for authorizing applications and devices. In this case, authorizing my desktop (device) was the best option. First, run the following command on the terminal in VS Code. Or open a terminal and go to sfdx project directory.
Make sure that you specify -r or –instanceurl flag. Sandboxes use the test.salesforce.com.
The outcome of a successful authenticated device follows.
▶ sfdx force:auth:device:login -r https://test.salesforce.com
=== Action Required!
Enter <CODE> user code in the verification URL https://test.salesforce.com/setup/connect
Login successful for testuser@test.com. You can now close the browser.
Final Step
In VS Code, command palette, select SFDX:Authorize an Org. You should see your org listed in the command box. Select the org and you are all set.
Just in case, here’s the command that VS Code runs behind the scenes. You can run the command in liue of the VS Code approach.