switching-org

Switches the default Salesforce CLI target org for project or global scope.

1|Updated May 7, 2026
One-click install
npx skills add https://github.com/amanpraaj/sf-skill-hub --skill switching-org-amanpraaj
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: switching-org
Source: https://github.com/amanpraaj/sf-skill-hub/tree/main/skills/salesforce/switching-org
Command: npx skills add https://github.com/amanpraaj/sf-skill-hub --skill switching-org-amanpraaj

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? When working across multiple Salesforce orgs (scratch orgs, sandboxes, production), CLI commands run against whichever org is set as the default. This Skill changes that default target-org so subsequent sf CLI commands execute against the correct org. ## Core Features & Use Cases - Set Default Org: Runs sf config set target-org <orgIdentifier> to point CLI commands at a specific username or alias. - Scope Control: Uses local (project-level) scope by default, with global scope only when explicitly requested. - Org Discovery: Lists authenticated orgs via sf org list when no identifier is provided, then verifies the result with sf config get target-org --json. - Use Case: You finished testing in a scratch org and need to deploy to a sandbox. Ask to switch the default org to the sandbox alias, and all subsequent CLI commands target it. ## Quick Start Switch my default Salesforce org to the alias 'dev-sandbox' and verify the change.

Frequently Asked Questions about switching-org

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I change the default org in Salesforce CLI?▼

Run `sf config set target-org <username-or-alias>` to set the default org for the current project directory. Add the `--global` flag only if you want the setting to apply system-wide across all directories.

How to switch between scratch org and sandbox in sf CLI?▼

Use `sf config set target-org <alias>` with the alias of the scratch org or sandbox you want to target. If you are unsure of the alias, run `sf org list` to see all authenticated orgs first.

Does sf config set support local and global scope?▼

Yes. Local scope (current project directory) is the default behavior of `sf config set`. Global scope requires the explicit `--global` flag. There are no `--local` or `--scope` flags in the unified sf CLI.

Why does my Salesforce org not change after setting target-org?▼

Check whether the SF_TARGET_ORG environment variable is set, because environment variables override config values. Also verify the org is authenticated by running `sf org list`, and re-authorize with `sf org login web` if needed.

Can I still use defaultusername from sfdx in the new sf CLI?▼

No. Legacy sfdx config keys like `defaultusername` and `defaultdevhubusername` are deprecated in the unified CLI. Use `target-org` and `target-dev-hub` instead.