4

When using the Saleseforce UI, it is possible to change a user's email and send them a password at the same time by changing the email and clicking 'Generate new password and notify user immediately' checkbox before saving. This avoids sending 2 emails (one for email change and one for password reset).

Is there a similar way to do this using Apex code that could be run in a SandboxPostCopy class?

I know it is possible to reset a user's password using System.resetPassword(userId, true);. I'm not sure how to go about doing the email update at the same time to avoid sending the password reset to the wrong email.

2

No, at least not in my attempts at this.

The methods to reset or set a password for a user immediately acts. There's no way to chain it with the update of the user's email.

Since they're separate transactions, the change of the user's email will always result in an email being sent to confirm this change regardless if you then call the reset or setPassword method.

Like you noted, even if you change the email on the user first, the password reset email will go to the original email as the change has not been confirmed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.