Dx Org Switch

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

作者 forcedotcome5164d94d7511c00fa02a5b8b60754b2361e178f無授權條款1K 個星標收錄於 2026年10月9日更新於 2026年10月9日儲存庫2 天前更新

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.

僅含說明DevOps & Cloud
AI 產生的概覽

使用 sf config set 切換 Salesforce CLI 目前的目標組織,並包含驗證步驟。

功能
此技能會引導代理變更 Salesforce CLI 指令所指向的 Salesforce 組織。它會以使用者名稱或別名辨識組織,透過 sf config set 在本機或全域設定預設 target-org,並以 sf config get target-org --json 驗證其值。它也涵蓋失敗處理,例如在組織可能尚未授權時建議執行 sf org login web,並說明 SF_TARGET_ORG 等環境變數會覆寫設定值。
適用情境
當有人想變更 Salesforce CLI 指令所指向的組織時使用,例如切換到 scratch org、sandbox 或正式環境組織。適合以「切換組織」、「變更預設組織」、「設定別名」或「指向」某個特定組織等說法提出的需求。
執行需求
需要 Salesforce CLI(sf)2.0.0 以上版本,以及一個已授權的組織;不包含指令碼,只有操作說明。CLI 指令需要網路存取,並須事先完成組織授權(例如透過 sf org login web)。

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

來源與署名

來源:forcedotcom/sf-skills位於plugins/builder/dx-org-lifecycle/skills/dx-org-switch提交e5164d9

授權條款: 無授權條款

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架