Community编程与开发github.com

forcedotcom/switching-org

使用 Salesforce CLI 切换活动的 Salesforce 组织(默认目标组织)。当用户想要更改 CLI 命令运行的目标组织时使用——无论是说“切换组织”、“更改默认组织”、“将我的组织设置为”、“使用别名”、“指向”,还是描述想要针对特定组织、Scratch 组织、沙盒或生产环境工作。

switching-org 是什么?

该技能用于通过 Salesforce CLI 切换活动的 Salesforce 组织(默认目标组织)。它允许开发者或 AI 代理在 Salesforce 项目工作中,根据需求动态更改 CLI 命令所针对的组织,例如从生产环境切换到沙盒或 Scratch 组织。此技能支持所有 Salesforce CLI 环境,包括 Salesforce DX、标准 Salesforce CLI 以及基于 JSON 的交互模式。其工作原理是解析用户的自然语言指令(如“切换组织”、“更改默认组织”、“使用别名”等),然后执行相应的 `sf org set default` 或 `sfdx force:config:set` 命令来更新目标组织。它对于多组织工作流、测试以及在不同 Salesforce 环境之间进行切换的场景非常有用。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/forcedotcom/sf-skills/tree/main/skills/switching-org

Installed? Explore more 编程与开发 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

switching-org 是做什么的?

使用 Salesforce CLI 切换活动的 Salesforce 组织(默认目标组织)。当有人想要更改 CLI 命令运行的目标组织时使用——无论是说“切换组织”、“更改默认组织”、“将我的组织设置为”、“使用别名”、“指向”,还是描述想要针对特定组织、Scratch 组织、沙盒或生产环境工作。

使用场景

  • 开发者正在处理多个 Salesforce 组织(例如,一个用于开发,一个用于测试,一个用于生产)。
  • AI 助手检测到在不同 Salesforce 环境之间切换的请求。
  • 用户希望通过名称或别名快速切换当前上下文。
  • 在 CI/CD 流水线或本地开发环境中需要切换到特定组织。

工作原理

该技能通过调用 Salesforce CLI 命令 sf org set default(或较旧的 sfdx force:config:set)来更改默认目标组织。它接受组织的别名、用户名或 ID,并在执行切换后验证新默认组织的状态。

支持的 CLI 版本

  • Salesforce CLI v2(推荐):使用 sf org set default 命令。
  • Salesforce CLI v1(旧版):使用 sfdx force:config:set 命令。

依赖项

  • 必须安装 Salesforce CLI。
  • 目标组织必须已通过 sf org login 或等效方法进行身份验证。

示例

基本用法

# 切换到名为 "my-scratch-org" 的组织(别名)
sf org set default my-scratch-org

# 验证当前默认组织
sf org display

使用旧版 CLI

# 使用用户名设置默认组织(旧版)
sfdx force:config:set [email protected]

# 查看当前配置
grep defaultusername .sfdx/sfdx-config.json

通过别名切换

如果已使用别名,例如:

# 假设已设置别名
sf alias set my-org-alias [email protected]

# 使用别名切换
sf org set default my-org-alias

常见问题

如何查看可用组织列表?

# 列出所有已授权的组织
sf org list

如何创建新别名?

# 为现有组织添加别名
sf alias set my-new-alias [email protected]

切换组织后如何验证?

# 显示当前默认组织详细信息
sf org display

注意事项

  • 切换默认组织只会影响后续的 CLI 命令,不会影响正在进行的操作或已打开的用户界面。
  • 如果指定了不存在的组织,命令将失败并显示错误消息。
  • 确保在切换前已妥善保存所有未提交的更改,因为某些命令可能依赖于特定的组织上下文。
  • 对于生产组织,请确保拥有适当的权限;误用可能导致意外数据修改。

故障排除

错误:"Organization not found"

确保你已登录到该组织。使用以下命令登录:

# 交互式登录
sf org login

# 使用客户端 ID 和密钥进行非交互式登录
sf org login --client-id YOUR_CLIENT_ID --private-key PATH_TO_KEY

错误:"Multiple matches found"

如果多个组织具有相似名称或别名,请使用完整的用户名或组织 ID 代替。

仍然有问题?

检查 Salesforce CLI 版本:

sf --version

并确保已安装:

sf plugins --core

如果问题仍然存在,请查阅 Salesforce CLI 文档 获取更多帮助。

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

forcedotcom/building-sf-integrations

Salesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), data import/export (use handling-sf-data), or CDC channel-membership metadata such as PlatformEventChannel, PlatformEventChannelMember, or EnrichedField (use managing-cdc-enablement).

forcedotcom/building-ui-bundle-app

MUST activate when the user wants to build, create, or generate a React application, React app, web application, single-page application (SPA), or frontend application — even if no project files exist yet. MUST also activate when the project contains a uiBundles/*/src/ directory or sfdx-project.json and the prompt says create, build, construct, or generate a new app, site, or page from scratch — even if the prompt also describes visual styling. MUST also activate when the task spans more than one ui-bundle skill. Use this skill when building a complete app end-to-end. Do NOT use for Lightning Experience apps with custom objects (use generating-lightning-app). Do NOT use for single-concern edits to an existing page (use building-ui-bundle-frontend).

forcedotcom/building-ui-bundle-frontend

MUST activate before editing ANY file under uiBundles/*/src/ for visual or UI changes to an EXISTING app — pages, components, sections, layout, styling, colors, fonts, navigation, animations, or any look-and-feel change. Use this skill when modifying pages, components, layout, styling, or navigation in an existing UI bundle app. Activate when the project contains appLayout.tsx, routes.tsx, src/pages/, src/components/, or global.css. This skill contains critical project-specific conventions (appLayout.tsx shell, shadcn/ui components, Tailwind CSS, Salesforce base-path routing, module restrictions) that override general knowledge. Without this skill, generated code will use wrong imports, break routing, or ignore project structure. Do NOT use when creating a new app from scratch (use building-ui-bundle-app instead).

forcedotcom/configuring-connected-apps

Salesforce Connected Apps and External Client Apps OAuth configuration with 120-point scoring. Use this skill to configure OAuth flows, JWT bearer auth, Connected Apps, and External Client Apps in Salesforce. TRIGGER when: user configures OAuth flows, JWT bearer auth, Connected Apps, ECAs, or touches .connectedApp-meta.xml / .eca-meta.xml files. DO NOT TRIGGER when: configuring Named Credentials for callouts (use building-sf-integrations), reviewing permission policies (use deploying-metadata), or writing Apex token-handling code (use generating-apex).

forcedotcom/debugging-apex-logs

Salesforce debug log analysis and troubleshooting with 100-point scoring. TRIGGER when: user analyzes debug logs, hits governor limits, reads stack traces, or touches .log files from Salesforce orgs. DO NOT TRIGGER when: running Apex tests (use running-apex-tests), generating or fixing Apex code (use generating-apex), or Agentforce session tracing (use observing-agentforce).

forcedotcom/deploying-metadata

Salesforce DevOps automation using sf CLI v2. TRIGGER when: user deploys metadata, creates/manages scratch orgs or sandboxes, sets up CI/CD pipelines, or troubleshoots deployment errors with sf project deploy. DO NOT TRIGGER when: writing Apex code (use generating-apex), building LWC components (use generating-lwc-components), creating metadata definitions (use generating-custom-object or generating-custom-field), or querying org data (use handling-sf-data).

forcedotcom/deploying-ui-bundle

MUST activate when the project contains a uiBundles/*/src/ directory or sfdx-project.json and the task involves deploying, pushing to an org, or post-deploy setup. Use this skill when deploying a UI bundle app to a Salesforce org. Covers the full deployment sequence: org authentication, pre-deploy build, metadata deployment, permission set assignment, data import, GraphQL schema fetch, and codegen. Activate when files like *.uibundle-meta.xml or sfdx-project.json exist and the user mentions deploying, pushing, org setup, or post-deploy tasks.

forcedotcom/developing-agentforce

Build, modify, debug, and deploy agents with Agentforce Agent Script. TRIGGER when: user creates, modifies, or asks about .agent files or aiAuthoringBundle metadata; changes agent behavior, responses, or conversation logic; designs agent actions, tools, subagents, or flow control; writes or reviews an Agent Spec; previews, debugs, deploys, publishes, or tests agents; uses Agent Script CLI commands (sf agent generate/preview/publish/test). DO NOT TRIGGER when: Apex development, Flow building, Prompt Template authoring, Experience Cloud configuration, or general Salesforce CLI tasks unrelated to Agent Script.

forcedotcom/fetching-salesforce-docs

Official Salesforce documentation retrieval skill. Use when you need authoritative Salesforce docs from developer.salesforce.com, help.salesforce.com, architect.salesforce.com, admin.salesforce.com, or lightningdesignsystem.com, especially when pages are JS-heavy, shell-rendered, or hard to extract with naive fetching. Use to ground answers in official Salesforce sources instead of third-party blogs or summaries. TRIGGER when: user asks for official Salesforce documentation, Apex or API reference, LWC docs, Agentforce docs, setup or help articles, or any doc from a Salesforce-owned domain. DO NOT TRIGGER when: user is asking for a code change, deployment task, or anything not requiring documentation retrieval — use the appropriate sf-* skill instead.

forcedotcom/generating-apex

Primary Apex authoring skill for class generation, refactoring, and review. ALWAYS ACTIVATE when the user mentions Apex, .cls, triggers, or asks to create/refactor a class (service, selector, domain, batch, queueable, schedulable, invocable, DTO, utility, interface, abstract, exception, REST resource). Use this skill for requests involving SObject CRUD, mapping collections, fetching related records, scheduled jobs, batch jobs, trigger design, @AuraEnabled controllers, @RestResource endpoints, custom REST APIs, or code review of existing Apex.

forcedotcom/generating-apex-test

Generate and validate Apex test classes with TestDataFactory patterns, bulk testing (251+ records), mocking strategies, assertion best practices, and disciplined test-fix loops. Use this skill when creating new Apex test classes, improving test coverage, debugging and fixing failing Apex tests, running test execution and coverage analysis, or implementing testing patterns for triggers, services, controllers, batch jobs, queueables, and integrations. Triggers on *Test.cls, *_Test.cls files, sf apex run test workflows, coverage reports, test-fix loops. Do NOT trigger for production Apex code (use generating-apex) or Jest/LWC tests.

forcedotcom/generating-custom-application

Use this skill when users need to create or configure tab-based Salesforce Custom Applications with navigation, branding, and action overrides. Trigger when users mention custom apps, application metadata, app navigation, or organizing tabs into applications. Use when users want to create app containers for tabs and pages. Do NOT use when the goal is hosting a React UI bundle in the App Launcher — use generating-ui-bundle-custom-app for that case.

forcedotcom/generating-custom-field

Use this skill when users need to create, generate, or validate Salesforce Custom Field metadata. Trigger when users mention custom fields, field types, Roll-up Summary fields, Master-Detail relationships, Lookup relationships, formula fields, picklists, or field metadata. Also use when users encounter field deployment errors, especially around Roll-up Summary format, Master-Detail constraints, or formula issues. Always use this skill for any custom field metadata work, field generation, or field troubleshooting.

forcedotcom/generating-custom-lightning-type

Use this skill when users need to create Custom Lightning Types (CLTs) for Einstein Agent actions or structured input/output schemas. Trigger when users mention CLT, Custom Lightning Types, Custom Lightning Types (CLTs) with widget/mosaic/fragment rendition/renderer, JSON schemas for agents, type definitions, lightning__objectType, or editor/renderer configurations. When widget renditions are requested, you MUST first read the widget-rendition.md reference file in this skill's references/ directory and follow its complete workflow. This is complex - always use this skill for CLT work.

forcedotcom/generating-custom-object

Use this skill when users need to create, generate, or validate Salesforce Custom Object metadata. Trigger when users mention custom objects, creating objects, object metadata, .object files, sharing models, name fields, or validation rules on objects. Also use when users say things like "create a custom object", "generate object metadata", "set up an object for...", or when they're troubleshooting object deployment errors especially around sharing models and Master-Detail relationships. Always use this skill for any custom object metadata work.

forcedotcom/generating-custom-tab

Use this skill when users need to create or configure Salesforce Custom Tabs. Trigger when users mention tabs, navigation tabs, object tabs, web tabs, Visualforce tabs, Lightning component tabs, app page tabs, or tab configuration. Also use when users want to add navigation to custom objects, create tabs for external content, or set up Lightning page tabs. Always use this skill for any custom tab work.

forcedotcom/generating-flexipage

Use this skill when users need to create, generate, modify, or validate Salesforce Lightning pages (FlexiPages). Trigger when users mention RecordPage, AppPage, HomePage, Lightning pages, page layouts, adding components to pages, or page customization. Also use when users say things like 'create a Lightning page', 'add a component to a page', 'customize the record page', 'generate a FlexiPage', or when they're working with FlexiPage XML files and need help with components, regions, or deployment errors. Always use this skill for any FlexiPage-related work, even if they just mention 'page' in the context of Salesforce.

forcedotcom/generating-flow

Generate Salesforce Flows using the MCP tool execute_metadata_action. Use when the user asks to create, build, or generate a flow — including Screen, Autolaunched, Record-Triggered (before/after-save), Scheduled. Also trigger for flow-like requests such as "when a record is created", "trigger daily at", "send an email when", "update the field when", "automate", "workflow", or "flow XML/metadata". This is the only skill for Salesforce Flow generation.

forcedotcom/generating-lightning-app

Build complete Salesforce Lightning Experience applications from natural language descriptions. Use this skill when a user requests a "complete app", "Lightning app", "business solution", "management system", or describes a scenario requiring multiple interconnected Salesforce components (objects, fields, pages, tabs, security). Orchestrates all required metadata types in proper dependency order to produce a deployable application.

forcedotcom/generating-list-view

Use this skill when users need to create, generate, or validate Salesforce List View metadata. Trigger when users mention list views, filtered record lists, creating views, setting up record columns, filtering records by criteria, or ask about list view visibility. Also use when users say things like "I need a view that shows...", "filter records by...", "create a list view for...", or when they're working with ListView XML files and need validation or troubleshooting.

相关技能