
Switching Org
Point Salesforce CLI commands at the right org alias or sandbox so deploys and queries stop hitting the wrong tenant.
Overview
switching-org is an agent skill for the Build phase that switches the Salesforce CLI default target-org using `sf config set` and verification.
Install
npx skills add https://github.com/forcedotcom/afv-library --skill switching-orgWhat is this skill?
- Sets `target-org` via `sf config set` with local project scope or explicit `--global` when requested
- Lists authenticated orgs with `sf org list` when the user does not supply an identifier
- Verifies with `sf config get target-org --json` and reports the active value clearly
- Documents Salesforce CLI (sf) v2+ compatibility and recovery hints such as `sf org login web`
- Distinguishes local default versus global scope because JSON verify output does not expose scope
- Salesforce CLI (sf) v2+ compatibility noted in skill metadata
Adoption & trust: 1.3k installs on skills.sh; 513 GitHub stars; 3/3 security scanners passed (skills.sh audits).
What problem does it solve?
You authenticated several Salesforce orgs and CLI commands keep running against the wrong sandbox or production alias.
Who is it for?
Salesforce developers alternating scratch orgs, sandboxes, and named aliases on one laptop.
Skip if: Org authentication from scratch (use login flows first) or teams managing org access only through CI secrets without local CLI.
When should I use this skill?
Whenever someone wants to change which Salesforce org CLI commands run against—switch org, change default org, set alias, or point to sandbox, scratch org, or production.
What do I get? / Deliverables
Your project-local or global `target-org` is set and verified so the next `sf` commands use the org you chose.
- Updated target-org configuration
- Verification message with active org identifier
Recommended Skills
Journey fit
Default org selection is daily Build and integration work whenever you use `sf` against Salesforce metadata or APIs. Salesforce org targeting is CLI integration configuration, not generic Git or frontend tooling.
How it compares
CLI config workflow for default org—not a replacement for `sf org login` or full deployment pipelines.
Common Questions / FAQ
Who is switching-org for?
Solo Salesforce builders using sf v2+ who need to retarget CLI commands without re-authenticating every session.
When should I use switching-org?
During Build integrations whenever you change sandboxes, pick a scratch org for the day, or align local CLI with the org your ticket references.
Is switching-org safe to install?
Review the Security Audits panel on this page; the skill only describes CLI config commands and does not store credentials itself.
SKILL.md
READMESKILL.md - Switching Org
## Steps 1. Identify the org: the user provides a username or alias (`orgIdentifier`). If not provided, run `sf org list` to show authenticated orgs and ask the user which one to use. 2. Set the default org: - Local (default): `sf config set target-org <orgIdentifier>` - Applies only within the current project directory. Use this for normal project work. - Global (only if user explicitly requests): `sf config set target-org <orgIdentifier> --global` - Applies system-wide across all directories. Use when working outside a project or when the user asks for global scope. - If this fails, report the error and suggest running `sf org login web` if the org may not be authorized. 3. Verify: - `sf config get target-org --json` - Note: the JSON output does not include a scope/location field — it cannot confirm whether the value is local or global. Confirm the value only, e.g.: `target-org is now set to: <value>` - If it fails, report the error and advise running `sf config get target-org`. ## Notes - Unified CLI uses keys like `target-org` and `target-dev-hub`. Legacy sfdx keys (`defaultusername`, `defaultdevhubusername`) are deprecated in this context. - The sf CLI does not have `--local` or `--scope` flags for config set. Local scope is the default behavior. - If the org does not change after setting the config, check whether `SF_TARGET_ORG` is set — environment variables override config values. - Salesforce CLI config (unified) reference: https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_config_commands_unified.htm#cli_reference_config_set_unified