SFDX: Retrieve This Source from Org (and Deploy This Source to Org) "failed to run" means the Salesforce CLI command that VS Code runs behind the scenes exited with an error. Run the same command in the terminal (sf project retrieve start or sf project deploy start) to see that error, then match it to the fixes below.
The other common outcome is a run that finishes cleanly and brings back nothing:
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, but the integrated terminal prints the CLI's own 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
Copy what the terminal prints and find it in the table below. When the error is vague, work through the numbered fixes further down, which are in the order I check them.
Error messages and what they mean
| Error text (exact) | What it means | Fix (section link) |
|---|---|---|
SFDX: Retrieve This Source from Org failed to run |
The CLI call errored. Rerun it in the terminal to see the real error. | 1, 2, 6 |
SFDX: Deploy This Source to Org failed to run |
The CLI call errored. Rerun it in the terminal to see the real error. | 1, 2, 6, Deploy |
No components retrieved |
The retrieve ran, but its scope matched nothing. | 1, 4, 5, package.xml |
Expected ComponentSet to be non-empty, but got size 0 (EmptyComponentSetError) |
The CLI found no components in the --source-dir, --metadata or --manifest scope it was given. |
ComponentSet, 3, 4, 5, package.xml |
No source-backed components present in the package. |
The same empty component set, on deploy. | ComponentSet, 4, 5 |
Error fetching metadata for org. Run "SFDX: Authorize an Org" to authorize your org again. |
The stored login is expired or invalid. | 2 |
The "force auth web login" command has been deprecated. Use "org login web" instead. |
You ran an old sfdx command. | 6 |
undefinedComponentSet |
A CLI bug on sf project deploy start --dry-run. |
undefinedComponentSet |
Expected ComponentSet to be non-empty, but got size 0
This EmptyComponentSetError means the CLI built the list of components to deploy or retrieve and the list was empty. Nothing in the path, metadata name or manifest you gave matched a source file inside your packageDirectories, so the command stopped before calling the org. Logging in again will not help, because the org was never contacted.
Check these:
- The right-clicked file or folder is under a
packageDirectoriespath (section 4). - It is not matched by a
.forceignorepattern (section 5). - VS Code is open on the folder that contains
sfdx-project.json(section 3). --metadatauses the exactType:Name, for exampleApexClass:MyClass.package.xmlmembers match the API names in the org (package.xml section).
My first move is to retrieve the component by name, because that does not depend on where the file sits locally:
sf project retrieve start --metadata ApexClass:InvoiceService
If that works and the right-click retrieve does not, the problem is the local path or workspace, and the first three checks above will find it. The cost of this shortcut: if your local copy sat outside the package directories, the retrieve writes a fresh copy into the default package directory and you can end up with two versions to reconcile.
The source-deploy-retrieve library's messages file has its own wording for an empty set: No source-backed components present in the package. on a deploy, and No components in the package to retrieve. on a retrieve. Work through the same checks for either one.
undefinedComponentSet on deploy --dry-run
CLI versions 2.94.6 to 2.97.5 threw Error (SfError): undefinedComponentSet on sf project deploy start --dry-run against recently refreshed sandboxes (forcedotcom/cli#3336). The project itself was fine: the same deploy without --dry-run went through, and v2.94.5 did not have the problem. Salesforce fixed it in sf v2.97.6 (July 2025), so run sf update and check sf --version before you change anything in the project.
SFDX: Deploy This Source to Org failed to run
Deploy This Source to Org wraps sf project deploy start --source-dir <path>, using the file or folder you right-clicked. The same causes 1 to 6 below apply, and an empty scope produces the ComponentSet error above.
Deploy has one cause of its own: the org rejected the component, for example because of an Apex compile error. The terminal run prints the component-level errors (component name, line and problem) that the VS Code panel can hide:
sf project deploy start --source-dir force-app/main/default/classes/MyClass.cls
Add --dry-run to validate the deploy without saving anything to the org.
1. No default org is set
VS Code retrieves from and deploys to 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. The wrong sandbox is also a common reason for "No components retrieved": the component exists in the org you meant, and you are connected to a different one.
2. The org login has expired
The error Error fetching metadata for org. Run "SFDX: Authorize an Org" to authorize your org again. means the stored login is no longer valid. 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 with SFDX: Authorize an Org, or from the terminal. 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
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 holds 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 works with paths listed under packageDirectories in sfdx-project.json. A minimal file looks like this (sourceApiVersion is an example value; use the version your project targets):
{
"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 and the deploy reports an empty component set. 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, because two CLIs on the PATH cause confusing failures. If your extensions updated recently, read what changed in Salesforce Extensions for VS Code v67.12.1. That release limits the Apex Language Server to valid project workspaces, so opening the wrong folder (section 3) now also turns off Apex language features.
Older guides use sfdx commands that current CLI versions reject or flag. The auth command prints The "force auth web login" command has been deprecated. Use "org login web" instead., and sfdx force:source:retrieve answers with Command force:source:retrieve not found. Copying them from an old answer adds errors of their own. The replacements:
sfdx force:source:retrieve → sf project retrieve start
sfdx force:source:deploy → sf project deploy start
sfdx force:auth:web:login → sf org login web
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. Some types cannot be retrieved through the Metadata API at all, so check the Metadata Coverage Report for types the CLI can't retrieve. If a large manifest retrieve stops with Entity expansion limit exceeded, that has a separate fix.
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.
What to watch for
.forceignoreskips files silently, so a rule added months ago can look like a broken retrieve.- A wrong default org gives no error at all, only "No components retrieved". Before you edit
.forceignore, runsf config get target-org. A default org still pointing at an older sandbox looks exactly like an ignored file. undefinedComponentSeton--dry-runwas a CLI bug. Update the CLI before you restructure the project.
Checklist
- Copy the exact error text and find it in the error table above.
- Run
sf project retrieve start(orsf project deploy start) in 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