Salesforce communities come with an inbuilt password change functionality. However, we can override this functionality to implement a custom password change page for users to provide them with a more personalized outlook. For this, we can either customize the default password template in Visualforce or create new password change pages to use in place of the default page.
In order to achieve this, we first need to disable the default functionality of ‘Send Welcome Email’ of the communities and send our custom email instead, when a community user is created. The email can contains the link to the community which redirects the user to the custom Password Change Visualforce Page.
In the custom page, resetPassword() method of System class is used to generate a new password for a specified user. This method takes in two parameters: userId, which is the id of the user whose password is to be reset and a Boolean type parameter sendUserEmail, which determines whether the user is to be notified that his password has been reset or not.
The return value for this method is of type System.ResetPasswordResult. It represents the result of password reset. getPassword() method of ResetPasswordResult Class is used to return the password generated by resetPassword() call.
Syntax: ResetPasswordResult rpr =System.resetPassword(Id userId, Boolean sendUserEmail);
String password = rpr.getPassword();
Here’s the step by step guide for doing the same:
- Go to Setup. In the quick find box, type Communities and select All Communities.
- Click on Manage button for the community for which this functionality is to be implemented.
- Click Administration→Emails and deselect the ‘Send Welcome Email’ checkbox.
- Add the custom page to Visualforce Site Pages.
- Go to ‘Login & Registration’ and scroll to Password section. Select ‘Visualforce page’ in the Change password drop down list. Click on the lookup icon and select the desired visualforce page and save.
Voila! You’re done!