@salesforce/plugin-user

中文文档
6.0.11发布于 2026/11/02Apache-2.0ES Module构建来源已验证

与用户和权限集交互的命令

中文使用文档
文档目录13 节
  1. 安装
  2. 问题
  3. 贡献
  4. 班
  5. 构建
  6. 测试
  7. 命令
  8. sf org assign permset
  9. sf org assign permsetlicense
  10. sf org create user
  11. sf org display user
  12. sf org generate password
  13. sf org list users

plugin-user

NPM Downloads/week License

在scratch组织中与用户和权限集交互的命令

这个插件与 Salesforce CLI。有关CLI的更多信息,请阅读 入门指南.

我们总是建议使用与CLI捆绑在一起的这些命令的最新版本,但是,如果需要,您可以安装特定的版本或标记。

安装

sfdx plugins:install [email protected]

问题

如有任何问题,请在 https://github.com/forcedotcom/cli/issues

贡献

  1. 请参阅我们的 行为准则
  2. 在开始项目之前创建一个新问题,以便我们可以跟踪 您想要添加/修复的内容。这样,我们也可以提供建议或 让你知道是否已经有了进展。
  3. Fork这个存储库。
  4. 在本地构建插件
  5. 创建一个 主题 把你的叉子分叉。注意,这个步骤是推荐的,但如果使用fork来贡献代码,从技术上讲不是必需的。
  6. 编辑您的分支中的代码。
  7. 为您的更改编写适当的测试。尝试在任何新代码上实现至少95%的代码覆盖率。没有单元测试,任何pull请求都不会被接受。
  8. 签署CLA(参见 班 下文)。
  9. 当你完成后,发送给我们一个拉请求。我们将审查您的代码,建议任何需要的更改,并将其合并。

班

外部贡献者将被要求签署贡献者许可证 协议。你可以这样做,去 https://cla.salesforce.com/sign-cla.

构建

要在本地构建插件,请确保安装了yarn并运行以下命令:

# Clone the repository
git clone [email protected]:salesforcecli/plugin-user

# Install the dependencies and compile
yarn install
yarn build

要使用您的插件,请使用本地 ./bin/dev 或者 ./bin/dev.cmd 文件。

# Run using local run file.
./bin/dev user

通过Salesforce CLI或使用本地运行文件运行时应该没有区别。但是,链接插件来做一些额外的测试或从机器上的任何地方运行命令可能是有用的。

# Link your plugin to the sfdx cli
sfdx plugins:link .
# To verify
sfdx plugins

测试

运行单元测试(模拟orgs和文件系统)

yarn test

运行非单元测试(真正的orgs,真正的FS)

# use your locally authenticated dev hub.  Supports both JWT and Refresh Token (web) auth
export TESTKIT_HUB_USERNAME=<username for dev hub>
yarn test:nuts

有关更多NUT选项和示例,请参见 https://github.com/salesforcecli/cli-plugins-testkit

命令

sf org assign permset

将权限集分配给一个或多个组织用户。

USAGE
  $ sf org assign permset -n <value>... -o <value> [--json] [--flags-dir <value>] [-b <value>...] [--api-version
  <value>]

FLAGS
  -b, --on-behalf-of=<value>...  Username or alias to assign the permission set to.
  -n, --name=<value>...          (required) Permission set to assign.
  -o, --target-org=<value>       (required) Username or alias of the target org. Not required if the `target-org`
                                 configuration variable is already set.
      --api-version=<value>      Override the api version used for api requests made by this command

GLOBAL FLAGS
  --flags-dir=<value>  Import flag values from a directory.
  --json               Format output as json.

DESCRIPTION
  Assign a permission set to one or more org users.

  To specify an alias for the --target-org or --on-behalf-of flags, use the CLI username alias, such as the one you set
  with the "alias set" command. Don't use the value of the Alias field of the User Salesforce object for the org user.

  To assign multiple permission sets, either set multiple --name flags or a single --name flag with multiple names
  separated by spaces. Enclose names that contain spaces in one set of double quotes. The same syntax applies to
  --on-behalf-of.

EXAMPLES
  Assign two permission sets called DreamHouse and CloudHouse to original admin user of your default org:

    $ sf org assign permset --name DreamHouse --name CloudHouse

  Assign the Dreamhouse permission set to the original admin user of the org with alias "my-scratch":

    $ sf org assign permset --name DreamHouse --target-org my-scratch

  Assign the Dreamhouse permission set to the specified list of users of your default org:

    $ sf org assign permset --name DreamHouse --on-behalf-of [email protected] --on-behalf-of user2 --on-behalf-of user

看代码: src /命令/ org/assign/permset.ts

sf org assign permsetlicense

将权限集许可证分配给一个或多个组织用户。

USAGE
  $ sf org assign permsetlicense -n <value>... -o <value> [--json] [--flags-dir <value>] [-b <value>...] [--api-version
  <value>]

FLAGS
  -b, --on-behalf-of=<value>...  Usernames or alias to assign the permission set license to.
  -n, --name=<value>...          (required) Name of the permission set license to assign.
  -o, --target-org=<value>       (required) Username or alias of the target org. Not required if the `target-org`
                                 configuration variable is already set.
      --api-version=<value>      Override the api version used for api requests made by this command

GLOBAL FLAGS
  --flags-dir=<value>  Import flag values from a directory.
  --json               Format output as json.

DESCRIPTION
  Assign a permission set license to one or more org users.

  To specify an alias for the --target-org or --on-behalf-of flags, use the CLI username alias, such as the one you set
  with the "alias set" command. Don't use the value of the Alias field of the User Salesforce object for the org user.

  To assign multiple permission sets, either set multiple --name flags or a single --name flag with multiple names
  separated by spaces. Enclose names that contain spaces in one set of double quotes. The same syntax applies to
  --on-behalf-of.

EXAMPLES
  Assign the DreamHouse permission set license to original admin user of your default org:

    $ sf org assign permsetlicense --name DreamHouse

  Assign two permission set licenses to the original admin user of the org with alias "my-scratch":

    $ sf org assign permsetlicense --name DreamHouse --name CloudHouse --target-org my-scratch

  Assign the Dreamhouse permission set license to the specified list of users of your default org:

    $ sf org assign permsetlicense --name DreamHouse --on-behalf-of [email protected] --on-behalf-of user2 --on-behalf-of \
      user3

看代码: src /命令/ org/assign/permsetlicense.ts

sf org create user

为scratch组织创建一个用户。

USAGE
  $ sf org create user -o <value> [--json] [--flags-dir <value>] [-a <value>] [-f <value>] [-s] [--api-version
    <value>]

FLAGS
  -a, --set-alias=<value>        Set an alias for the created username to reference in other CLI commands.
  -f, --definition-file=<value>  File path to a user definition file for customizing the new user.
  -o, --target-org=<value>       (required) Username or alias of the target org. Not required if the `target-org`
                                 configuration variable is already set.
  -s, --set-unique-username      Force the username, if specified in the definition file or at the command line, to be
                                 unique by appending the org ID.
      --api-version=<value>      Override the api version used for api requests made by this command

GLOBAL FLAGS
  --flags-dir=<value>  Import flag values from a directory.
  --json               Format output as json.

DESCRIPTION
  Create a user for a scratch org.

  A scratch org includes one administrator user by default. For testing purposes, however, you sometimes need to create
  additional users.

  The easiest way to create a user is to let this command assign default or generated characteristics to the new user.
  If you want to customize your new user, create a definition file and specify it with the --definition-file flag. In
  the file, you can include all the User sObject (Salesforce object) fields and Salesforce DX-specific options, as
  described in "User Definition File for Customizing a Scratch Org User"
  (https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_scratch_orgs_users_def_file.htm).
  You can also specify these options on the command line.

  If you don't customize your new user, this command creates a user with the following default characteristics:

  * The username is the existing administrator’s username prepended with a timestamp, such as
  [email protected].
  * The user’s profile is Standard User.
  * The values of the required fields of the User sObject are the corresponding values of the administrator user.
  * The user has no password.

  Use the --set-alias flag to assign a simple name to the user that you can reference in later CLI commands. This alias
  is local and different from the Alias field of the User sObject record of the new user, which you set in the Setup UI.

  When this command completes, it displays the new username and user ID. Run the "org display user" command to get more
  information about the new user.

  After the new user has been created, Salesforce CLI automatically authenticates it to the scratch org so the new user
  can immediately start using the scratch org. The CLI uses the same authentication method that was used on the
  associated Dev Hub org.

  For more information about user limits, defaults, and other considerations when creating a new scratch org user, see
  https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_scratch_orgs_users.htm.

ALIASES
  $ sf force user create

EXAMPLES
  Create a user for your default scratch org and let this command generate a username, user ID, and other
  characteristics:

    $ sf org create user

  Create a user with alias "testuser1" using a user definition file. Set the "profileName" option to "Chatter Free
  User", which overrides the value in the defintion file if it also exists there. Create the user for the scratch org
  with alias "my-scratch":

    $ sf org create user --set-alias testuser1 --definition-file config/project-user-def.json profileName='Chatter \
      Free User' --target-org my-scratch

  Create a user by specifying the username, email, and perm set assignment at the command line; command fails if the
  username already exists in Salesforce:

    $ sf org create user [email protected] [email protected] permsets=DreamHouse

  Create a user with a definition file, set the email value as specified (overriding any value in the definition
  file), and generate a password for the user. If the username in the definition file isn't unique, the command
  appends the org ID to make it unique:

    $ sf org create user --definition-file config/project-user-def.json [email protected] generatepassword=true \
      --set-unique-username

FLAG DESCRIPTIONS
  -f, --definition-file=<value>  File path to a user definition file for customizing the new user.

    The user definition file uses JSON format and can include any Salesforce User sObject field and Salesforce
    DX-specific options. See
    https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_scratch_orgs_users_def_file.htm
    for more information.

  -s, --set-unique-username

    Force the username, if specified in the definition file or at the command line, to be unique by appending the org
    ID.

    The new user’s username must be unique across all Salesforce orgs and in the form of an email address. If you let
    this command generate a username for you, it's guaranteed to be unique. If you specify an existing username in a
    definition file, the command fails. Set this flag to force the username to be unique; as a result, the username
    might be different than what you specify in the definition file.

看代码: src /命令/ org/create/user.ts

sf org display user

显示Salesforce用户的信息。

USAGE
  $ sf org display user -o <value> [--json] [--flags-dir <value>] [--api-version <value>]

FLAGS
  -o, --target-org=<value>   (required) Username or alias of the target org. Not required if the `target-org`
                             configuration variable is already set.
      --api-version=<value>  Override the api version used for api requests made by this command

GLOBAL FLAGS
  --flags-dir=<value>  Import flag values from a directory.
  --json               Format output as json.

DESCRIPTION
  Display information about a Salesforce user.

  Output includes the profile name, org ID, instance URL, login URL, and alias if applicable. The displayed alias is
  local and different from the Alias field of the User sObject record of the new user, which you set in the Setup UI.

ALIASES
  $ sf force user display

EXAMPLES
  Display information about the admin user of your default scratch org:

    $ sf org display user

  Display information about the specified user and output in JSON format:

    $ sf org display user --target-org [email protected] --json

看代码: src /命令/ org/display/user.ts

sf org generate password

为scratch org用户生成一个随机密码。

USAGE
  $ sf org generate password -o <value> [--json] [--flags-dir <value>] [-b <value>...] [-l <value>] [-c <value>]
    [--api-version <value>]

FLAGS
  -b, --on-behalf-of=<value>...  Comma-separated list of usernames or aliases to assign the password to; must have been
                                 created locally with the "org create user" command.
  -c, --complexity=<value>       [default: 5] Level of password complexity or strength; the higher the value, the
                                 stronger the password.
  -l, --length=<value>           [default: 20] Number of characters in the generated password; valid values are between
                                 20 and 1000. Default value is 20.
  -o, --target-org=<value>       (required) Username or alias of the target org. Not required if the `target-org`
                                 configuration variable is already set.
      --api-version=<value>      Override the api version used for api requests made by this command

GLOBAL FLAGS
  --flags-dir=<value>  Import flag values from a directory.
  --json               Format output as json.

DESCRIPTION
  Generate a random password for scratch org users.

  By default, new scratch orgs contain one admin user with no password. Use this command to generate or change a
  password for this admin user. After it's set, you can’t unset a password, you can only change it.

  You can also use the --on-behalf-of flag to generate a password for a scratch org user that you've created locally
  with the "org create user" command. This command doesn't work for users you created in the scratch org using Setup.

  To change the password strength, set the --complexity flag to a value between 3 and 5. Each value specifies the types
  of characters used in the generated password:

  3 - lower and upper case letters and numbers only
  4 - lower and upper case letters and symbols only
  5 - lower and upper case letters and numbers and symbols only

  To see a password that was previously generated, run "org auth show-user-password".

EXAMPLES
  Generate a password for the original admin user of your default scratch org:

    $ sf org generate password

  Generate a password that contains 25 characters for the original admin user of the scratch org with alias
  "my-scratch":

    $ sf org generate password --length 25 --target-org my-scratch

  Generate a password for your default scratch org admin user that uses lower and upper case letters and numbers only:

    $ sf org generate password --complexity 3

  Generate a password for the specified users in the default scratch org; these users must have been created locally
  with the "org create user" command:

    $ sf org generate password --on-behalf-of [email protected] --on-behalf-of [email protected] --on-behalf-of [email protected]

看代码: src /命令/ org/generate/password.ts

sf org list users

列出组织的所有本地认证用户。

USAGE
  $ sf org list users -o <value> [--json] [--flags-dir <value>] [--api-version <value>]

FLAGS
  -o, --target-org=<value>   (required) Username or alias of the target org. Not required if the `target-org`
                             configuration variable is already set.
      --api-version=<value>  Override the api version used for api requests made by this command

GLOBAL FLAGS
  --flags-dir=<value>  Import flag values from a directory.
  --json               Format output as json.

DESCRIPTION
  List all locally-authenticated users of an org.

  For scratch orgs, the list includes any users you've created with the "org create user" command; the original scratch
  org admin user is marked with "(A)". For other orgs, the list includes the users you used to authenticate to the org.

ALIASES
  $ sf force user list

EXAMPLES
  List the locally-authenticated users of your default org:

    $ sf org list users

  List the locally-authenticated users of the specified org:

    $ sf org list users --target-org [email protected]

看代码: src /命令/ org/list/users.ts

版本与发布记录

@salesforce/plugin-user 共发布 290 个版本,首次发布于 2020/11/19;过去 12 个月发布了 63 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
6.0.11latest2026/11/021 天前
6.0.102026/11/021 天前
6.0.92026/11/012 天前
6.0.82026/11/012 天前
6.0.72026/10/294 天前
6.0.62026/10/268 天前

其他发布通道:beta → 1.2.2-ctc-testing-2.2。

关于 @salesforce/plugin-user 的常见问题

@salesforce/plugin-user 是什么?

与用户和权限集交互的命令

如何安装 @salesforce/plugin-user?

在项目目录运行 npm install @salesforce/plugin-user,或使用 pnpm add / yarn add / bun add。

@salesforce/plugin-user 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/salesforce__plugin-user 是否存在。

@salesforce/plugin-user 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@salesforce/plugin-user 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@salesforce/plugin-user 可以商用吗?

@salesforce/plugin-user 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@salesforce/plugin-user 还在维护吗?

最新版本 6.0.11 发布于 2026/11/02(1 天前);至今共发布 290 个版本,其中过去 12 个月发布了 63 个;首次发布于 2020/11/19。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。