Options
All
  • Public
  • Public/Protected
  • All
Menu

A class for creating a User, generating a password for a user, and assigning a user to one or more permission sets. See methods for examples.

Hierarchy

  • User

Index

Methods

assignPassword

  • Assigns a password to a user. For a user to have the ability to assign their own password, the org needs the following org preference: SelfSetPasswordInApi

    Parameters

    • info: AuthInfo

      The AuthInfo object for user to assign the password to.

    • Default value password: SecureBuffer<void> = User.generatePasswordUtf8()

      A SecureBuffer containing the new password.

    Returns Promise<Object>

assignPermissionSets

  • assignPermissionSets(id: string, permsetNames: string[]): Promise<void>
  • Methods to assign one or more permission set names to a user.

    example

    const org = await Org.create(await Connection.create(await AuthInfo.create('standardUser'))); const user: User = await User.init(org) const fields: UserFields = await user.retrieve(); await user.assignPermissionSets(fields.id, ['sfdx', 'approver']);

    Parameters

    • id: string

      The Salesforce id of the user to assign the permission set to.

    • permsetNames: string[]

      An array of permission set names.

    Returns Promise<void>

create

  • Method for creating a new User.

    By default scratch orgs only allow creating 2 additional users. Work with Salesforce Customer Service to increase user limits.

    The Org Preferences required to increase the number of users are: Standard User Licenses Salesforce CRM Content User

    example

    const org = await Org.create(await Connection.create(await AuthInfo.create('fooUser'))); const fields: UserFields = await DefaultUserFields.init(org); const user: User = await User.init(org); const info: AuthInfo = await user.create(fields);

    Parameters

    • fields: UserFields

      The required fields for creating a user.

    Returns Promise<AuthInfo>

    An AuthInfo object for the new user.

retrieve

  • Method to retrieve the UserFields for a user.

    example

    const org = await Org.create(await Connection.create(await AuthInfo.create('fooUser'))); const user: User = await User.init(org); const fields: UserFields = await user.retrieve('boris@thecat.com')

    Parameters

    • username: string

      The username of the user

    Returns Promise<UserFields>

Static generatePasswordUtf8

  • Generate default password for a user.

    Returns SecureBuffer<void>

    An encrypted buffer containing a utf8 encoded password.

Static init

  • Initialize a new instance of a user.

    Parameters

    • org: Org

      The org associated with the user.

    Returns Promise<User>

    A user instance