SFDX: Retrieve This Source from Org is a thin wrapper around the Salesforce CLI. When it fails, VS Code shows either "failed to run" or a run that finishes with nothing retrieved:
12:35:51.377 Starting SFDX: Retrieve This Source from Org
No components retrieved
12:35:51.396 Ended SFDX: Retrieve This Source from Org
Neither message says why. The fastest way to find out is to run the same retrieve in the integrated terminal, where the CLI prints the real error:
# Retrieve one file
sf project retrieve start --source-dir force-app/main/default/classes/MyClass.cls
# Or retrieve by metadata name
sf project retrieve start --metadata ApexClass:MyClass
The error you get points at one of the six causes below. They are in the order I check them.
1. No default org is set
VS Code retrieves from the project's default org. If none is set, the command fails to run.
sf config get target-org
If that comes back empty, or names a different org than you expect, set it:
sf config set target-org MyDevSandbox
You can also click the org name in the VS Code status bar, or run SFDX: Set a Default Org from the command palette. Retrieving from the wrong sandbox is also a common reason for "No components retrieved": the component exists in the org you meant, not the one you are connected to.
2. The org login has expired
Refresh tokens expire, sandboxes get refreshed and users get deactivated. List your orgs and look at the connection status:
sf org list
If the target org shows an expired or invalid session, log in again and keep the same alias so the project config still matches:
sf org login web --alias MyDevSandbox --instance-url https://mycompany--dev.sandbox.my.salesforce.com
In VS Code the same thing is SFDX: Authorize an Org.
3. VS Code is open on the wrong folder
The Salesforce extensions look for sfdx-project.json at the root of the open workspace. If you opened a parent folder that contains several projects, or a subfolder such as force-app, the commands have no project to work with. Use File > Open Folder on the folder that contains sfdx-project.json.
4. The file is outside your package directories
The CLI only retrieves into paths listed under packageDirectories in sfdx-project.json:
{
"packageDirectories": [
{ "path": "force-app", "default": true }
],
"sourceApiVersion": "62.0"
}
If you right-click a file in a folder that is not listed, such as a scratch/ or src/ folder copied from another project, the retrieve finishes with nothing retrieved. Move the file under a package directory, or add the folder to packageDirectories.
5. .forceignore excludes it
Files that match a pattern in .forceignore are skipped on both deploy and retrieve, without an error. Open .forceignore at the project root and look for a broad pattern such as **/profiles or **/*.xml that covers your file. Remove or narrow the rule if you need that metadata.
6. The CLI or the extensions are out of date
The VS Code extensions call the CLI, so a stale or missing CLI breaks them. Check and update both:
sf --version
sf update
Then update the Salesforce Extension Pack from the Extensions view and reload the window. If you still have the old sfdx npm package installed alongside @salesforce/cli, uninstall it. Two CLIs on the PATH cause confusing failures.
Older guides use commands such as sfdx force:source:retrieve and sfdx force:auth:web:login. Current CLI versions answer the first with Command force:source:retrieve not found and flag the auth commands as deprecated, so copying them from an old answer adds errors of its own. The current equivalents are sf project retrieve start, sf org login web and sf org list.
Retrieving a set of components with package.xml
For more than a handful of files, retrieve with a manifest. Right-click manifest/package.xml and choose SFDX: Retrieve Source in Manifest from Org, or run:
sf project retrieve start --manifest manifest/package.xml
Member names in package.xml must match the API names in the org exactly, including the folder prefix for reports, dashboards and email templates (MyFolder/MyReport). A misspelled member is skipped, and the retrieve can finish with nothing retrieved.
Check the user's permissions
If the CLI reports an insufficient access error, the user you logged in as cannot use the Metadata API. Retrieving metadata needs API Enabled plus Modify Metadata Through Metadata API Functions or Modify All Data. Assign them through a permission set, or log in as a user who has them.
Checklist
- Run
sf project retrieve startin the terminal and read the error. sf config get target-orgnames the org you mean.sf org listshows that org as connected.- VS Code is open on the folder with
sfdx-project.json. - The file is inside a
packageDirectoriespath and soql-not-in-not-equal-exclusion/" class="auto-link">not in.forceignore. sf updateand the Salesforce Extension Pack are current.
Leave a Comment