function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Devendra SawantDevendra Sawant 

Create User

 

Hi,

I have created one vf page where i can create a User for my org. When i save a record after entering the required fields(Send EMail Notification functionality to that user is not works).

Is it because i am customizing Create User functionality on vf page?

Because when we create a User from Setup->Manage Users option salesforce automatically sends the email to that particular user.


Cheers,
Devendra S 

Shashikant SharmaShashikant Sharma

Before you insert user just set DML Option for sending email

 

Database.DMLOptions dmo = new Database.DMLOptions();
dmo.EmailHeader.triggerUserEmail = true
User newUser = new User();
// Fill all mandatory fields

newUser.setOptions(dmo);
insert newUser;

 let me know if any issues in it.

Amit Singh.ax1042Amit Singh.ax1042

Shashi it works well while creating new User....

but what about when user is created and after some time want to reset old one... then how we can write code to regenerate the password...

Thank you!!!

 

Shashikant SharmaShashikant Sharma

You can use system.resetpassword method

 



resetPasswordID userID

Boolean send_user_email

System.ResetPasswordResultResets the password for the specified user. When the user logs in with the new password, they are prompted to enter a new password and to select a security question and answer if they haven't already. If you specify true forsend_user_email, the user is sent an email notifying them that their password was reset. A link to sign onto Salesforce using the new password is included in the email. Use setPassword if you don't want the user to be prompted to enter a new password when they log in.Warning
Be careful with this method, and do not expose this functionality to end-users.
Amit Singh.ax1042Amit Singh.ax1042

Could you please show me any examle as you have shown earlier!!!

Amit Singh.ax1042Amit Singh.ax1042

Got the solution by using,

 System.ResetPasswordResult result = System.resetPassword(userId,true);

 

it will reset the password.