I have Apex-code which generates new user accounts, and it specifies a user-provided password for the account.
On first login the users are prompted to change the password, which is a painful extra step in our current workflow.
How do I prevent users being forced to set a new password?
My Apex looks like this:
User usr = new User(
<<fields populated>>
);
// Set the DML options to prevent e-mail to new user
Database.DMLOptions dlo = new Database.DMLOptions();
dlo.EmailHeader.triggerUserEmail = false;
//Insert new user
Database.SaveResult sr = Database.insert(usr,dlo);
if (sr.isSuccess()) {
String errString = '';
try {
//Get user Id
Id usr_sfid = sr.getId();
if (usr_sfid == null)
{
errString = 'Error setting password (username: ' + username + ') - Could not get Id to set User pwd.';
System.debug(errString);
}
else
{
System.setPassword(usr_sfid, usr_password);
}
}
catch(Exception e) {
errString = 'Error setting password (username: ' + username + ')' + e.getMessage();
System.debug(errString);
}