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.
The AuthInfo object for user to assign the password to.
[throwWhenRemoveFails = User.generatePasswordUtf8()] A SecureBuffer containing the new password.
Methods to assign one or more permission set names to a user.
The Salesforce id of the user to assign the permission set to.
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']);
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
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());
Method to retrieve the UserFields for a user.
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);
Static
generateGenerate default password for a user. Returns An encrypted buffer containing a utf8 encoded password.
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.