Skip to main content
New tool CRON Expression Builder — preview next run times before you schedule Apex. Open the builder →
Debugging an SFDX retrieve failure in VS Code showing successful execution but no retrieved components.
DevOps

SFDX: Retrieve This Source from Org Failed in VS Code? 6 Fixes

SFDX: Retrieve This Source from Org and SFDX: Deploy This Source to Org fail when the Salesforce CLI command behind them errors or finds no components. This guide matches each exact error, from 'failed to run' to 'Expected ComponentSet to be non-empty', to its cause and the sf command that fixes it.

The short answer

SFDX: Retrieve This Source from Org (and Deploy This Source to Org) "failed to run" means the Salesforce CLI command VS Code runs behind the scenes exited with an error. Run sf project retrieve start or sf project deploy start in the terminal to see that error, then match it to its fix.

Key takeaways Copy the exact error text. Each message (failed to run, No components retrieved, Expected ComponentSet to be non-empty, Error fetching metadata for org) points to a specific fix. Deploy This Source to Org fails for the same reasons as Retrieve, plus one of its own: the org rejecting the component, which only the terminal run shows in full. Run sf project retrieve start or sf project deploy start in the integrated terminal to see the CLI error that the VS Code panel hides. An empty ComponentSet is a local scope problem: wrong workspace folder, a file outside packageDirectories, a .forceignore match or a wrong Type:Name. Replace old sfdx force: commands with sf project retrieve start, sf project deploy start and sf org login web, and keep the CLI current with sf update.

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 packageDirectories path (section 4).
  • It is not matched by a .forceignore pattern (section 5).
  • VS Code is open on the folder that contains sfdx-project.json (section 3).
  • --metadata uses the exact Type:Name, for example ApexClass:MyClass.
  • package.xml members 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

  • .forceignore skips 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, run sf config get target-org. A default org still pointing at an older sandbox looks exactly like an ignored file.
  • undefinedComponentSet on --dry-run was a CLI bug. Update the CLI before you restructure the project.

Checklist

  1. Copy the exact error text and find it in the error table above.
  2. Run sf project retrieve start (or sf project deploy start) in the terminal and read the error.
  3. sf config get target-org names the org you mean.
  4. sf org list shows that org as connected.
  5. VS Code is open on the folder with sfdx-project.json.
  6. The file is inside a packageDirectories path and soql-not-in-not-equal-exclusion/" class="auto-link">not in .forceignore.
  7. sf update and the Salesforce Extension Pack are current.

Originally reported by reddit.com

Frequently asked questions

Why does SFDX: Retrieve This Source from Org fail to run?

The Salesforce CLI command that VS Code runs behind the scenes exited with an error. Run sf project retrieve start --source-dir <path> in the terminal to see it. The usual causes are no default org, an expired login or an outdated CLI.

Why does SFDX: Deploy This Source to Org fail to run?

It wraps sf project deploy start --source-dir <path>, so it fails for the same reasons as retrieve: default org, login, workspace folder, package directories, .forceignore or CLI version. It can also fail because the org rejected the component, for example with an Apex compile error, and the terminal run prints those component-level errors.

What does Expected ComponentSet to be non-empty, but got size 0 mean?

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.

How do I fix Error fetching metadata for org in VS Code?

The message means the stored login for the default org is expired or invalid. Run SFDX: Authorize an Org, or sf org login web with the same alias, so the project config still matches the org.

Why does SFDX retrieve say No components retrieved?

The command ran, but the scope it was given matched nothing it could retrieve. Usually the file sits outside the packageDirectories in sfdx-project.json, matches a .forceignore rule, or does not exist in the org you are connected to, for example because the default org points at a different sandbox.

What replaced sfdx force auth web login?

sf org login web replaced sfdx force:auth:web:login. The force:source commands are replaced too: sf project retrieve start for force:source:retrieve and sf project deploy start for force:source:deploy.

Newsletter

One email every Tuesday

New guides, tool updates, and the release-note changes that break things.

No spam. Unsubscribe in one click.

Comments

Loading comments...

Leave a Comment