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

When SFDX: Retrieve This Source from Org fails to run, or ends with No components retrieved, the cause is almost always one of six things: no default org, an expired login, the wrong folder open, a path outside your package directories, .forceignore, or a stale CLI.

The short answer

Run the same retrieve in the terminal with sf project retrieve start to see the real error. It is usually one of six causes: no default org set, an expired org login, VS Code opened on a folder other than the project root, a file outside the packageDirectories in sfdx-project.json, a .forceignore rule, or an outdated Salesforce CLI.

Key takeaways Reproduce the failure in the terminal with sf project retrieve start. The CLI prints the error the VS Code output panel hides. Check the default org with sf config get target-org and refresh the login with sf org login web. Open the folder that contains sfdx-project.json, not a parent or child folder. The file you retrieve must sit inside a path listed in packageDirectories and must not match .forceignore. Update the CLI with sf update and keep the Salesforce Extension Pack current. The extensions call the CLI, so a stale CLI breaks them.

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

  1. Run sf project retrieve start in the terminal and read the error.
  2. sf config get target-org names the org you mean.
  3. sf org list shows that org as connected.
  4. VS Code is open on the folder with sfdx-project.json.
  5. The file is inside a packageDirectories path and soql-not-in-not-equal-exclusion/" class="auto-link">not in .forceignore.
  6. 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 VS Code command is a wrapper around the Salesforce CLI. It fails to run when the CLI call errors, most often because no default org is set, the org login has expired, or the CLI is missing or outdated. Run sf project retrieve start in the integrated terminal to see the actual error message.

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.

How do I set the default org for VS Code?

Click the org name in the VS Code status bar, or run SFDX: Set a Default Org from the command palette. From the terminal, run sf config set target-org YourAlias in the project folder. Check it with sf config get target-org.

What permissions do I need to retrieve metadata?

The user needs API Enabled and either Modify Metadata Through Metadata API Functions or Modify All Data. A user without those can log in through the CLI but cannot retrieve metadata.

Do the old sfdx force commands still work?

Not reliably. Current Salesforce CLI versions no longer have force:source:retrieve, and the force:auth commands are deprecated. Use sf project retrieve start, sf org login web and sf org list instead.

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