Dx Org Switch

forcedotcom/sf-skills/plugins/builder/dx-org-lifecycle/skills/dx-org-switch

by forcedotcome5164d94d7511c00fa02a5b8b60754b2361e178fNo license1K starsListed Oct 9, 2026Updated Oct 9, 2026Repository updated yesterday

Switches the active Salesforce org (default target-org) using the Salesforce CLI. Use whenever someone wants to change which org CLI commands run against — whether they say "switch org", "change default org", "set my org to", "use alias", "point to", or describe wanting to work against a specific org, scratch org, sandbox, or production.

Instructions onlyDevOps & Cloud
AI-generated overview

Switches the active Salesforce CLI target org using sf config set, with verification steps.

What it does
This skill guides an agent through changing which Salesforce org the Salesforce CLI runs commands against. It identifies an org by username or alias, sets the default target-org locally or globally via sf config set, and verifies the value with sf config get target-org --json. It also covers failure handling, such as suggesting sf org login web when an org may not be authorized, and notes that environment variables like SF_TARGET_ORG override config values.
When to use it
Use it when someone wants to change the org that Salesforce CLI commands target, such as switching to a scratch org, sandbox, or production org. It fits requests phrased as switching org, changing the default org, setting an alias, or pointing to a specific org.
Requirements
Requires the Salesforce CLI (sf) version 2.0.0 or later and an authenticated org; no scripts are included, only instructions. Network access and prior org authorization (for example via sf org login web) are needed for the CLI commands to work.

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

Source and attribution

Source:forcedotcom/sf-skillsinplugins/builder/dx-org-lifecycle/skills/dx-org-switchat commite5164d9

License: No license

Content belongs to its original authors. SourceWeft indexes it from a public repository.

Report or request removal