@salesforce/core
    Preparing search index...

    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
    • Assigns a password to a user. For a user to have the ability to assign their own password, the org needs the following org feature: EnableSetPasswordInApi.

      Parameters

      • info: AuthInfo

        The AuthInfo object for user to assign the password to.

      • password: SecureBuffer<void> = ...

        [throwWhenRemoveFails = User.generatePasswordUtf8()] A SecureBuffer containing the new password.

      Returns 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>

    • 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>

    • Initialize a new instance of a user and return it.

      Returns Promise<void>

    • 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>