Options
All
  • Public
  • Public/Protected
  • All
Menu

Class User

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

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.

    Parameters

    • id: string

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

    • permsetNames: string[]

      An array of permission set names.

      const username = 'user@example.com';
      const connection: Connection = await Connection.create({
        authInfo: await AuthInfo.create({ username })
      });
      const org = await Org.create({ connection });
      const user: User = await User.create({ org });
      const fields: UserFields = await user.retrieve(username);
      await user.assignPermissionSets(fields.id, ['sfdx', 'approver']);

    Returns Promise<void>

createUser

  • 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

    Parameters

    • fields: UserFields

      The required fields for creating a user.

      const connection: Connection = await Connection.create({
        authInfo: await AuthInfo.create({ username: 'user@example.com' })
      });
      const org = await Org.create({ connection });
      
      const defaultUserFields = await DefaultUserFields.create({ templateUser: 'devhub_user@example.com' });
      const user: User = await User.create({ org });
      const info: AuthInfo = await user.createUser(defaultUserFields.getFields());

    Returns Promise<AuthInfo>

init

  • init(): Promise<void>
  • Initialize a new instance of a user and return it.

    Returns Promise<void>

retrieve

  • Method to retrieve the UserFields for a user.

    Parameters

    • username: string

      The username of the user.

      const username = 'boris@thecat.com';
      const connection: Connection = await Connection.create({
        authInfo: await AuthInfo.create({ username })
      });
      const org = await Org.create({ connection });
      const user: User = await User.create({ org });
      const fields: UserFields = await user.retrieve(username);

    Returns Promise<UserFields>

Static create

  • create<P, T>(this: object, options: P): Promise<T>
  • Asynchronously constructs and initializes a new instance of a concrete subclass with the provided options.

    Type parameters

    • P

    • T: AsyncCreatable<P>

    Parameters

    • this: object
    • options: P

      An options object providing initialization params to the async constructor.

    Returns Promise<T>

Static generatePasswordUtf8

  • Generate default password for a user. Returns An encrypted buffer containing a utf8 encoded password.

    Returns SecureBuffer<void>