Manually Setup a User’s Password in Salesforce using Developer Console or the Workbench.
There are times when an Administrator needs to manually setup a users password in Salesforce. Salesforce Administrator’s can reset a User’s password from the User record detail page but Salesforce user interface doesn’t allow an Administrator to setup a specific password. Here is an Awesome Admin Hack to achieved this using the Developer Console or the Workbench.
Let’s discuss each method step by step.
Manually Setup a User’s Password in Salesforce Using the Developer Console.
Step 1. Get the User’s Id from the URL bar on the User’s record detail page.
Step 2. Open Developer Console
Step 3. Open the Execute Anonymous Window from Debug >> Open Execute Anonymous Window OR using the shortcut Ctrl + E
Step 4. Enter the following Apex code. Replace the UserId and Password with the actual values we need.
System.SetPassword('UserId','Password'); //Replace the UserId and Password
Step 5. Click Execute
We successfully manually setup the User’s password using the developer console and an email with the new security token will is emailed to the User.
Manually Setup a User’s Password in Salesforce Using Workbench.
- Visit Workbench (https://workbench.developerforce.com/login.php) and Login using your Salesforce credentials.
- Navigate to Utilities >> Password Management
- Enter the User’s Id and the New Password
- Click on Change Password
We successfully manually setup the User’s password using Workbench and an email with the new security token will is emailed to the User.
Pro Tip: Creating a User Interface to manually setup a User’s password in Salesforce.
Step 1. Create a New Text Field on the User Object and Name it Password__c
Step 2. Create the following trigger on the User object
trigger setPassword on User (before update) { for (User u:Trigger.New) { User oldUser = Trigger.OldMap.get(u.id); If ((u.Password__c != null) && (oldUser.Password__c != u.Password__c)) { System.SetPassword(u.id,u.password__c); //Uncomment below line to clear password field //u.Password__c = null; } } }
Note: Use validation rules on Password__c to only accept passwords that align with your organization’s password policies.
Here’s how the trigger looks in the developer console (image)
Step 3. Now visit the User’s record detail page and enter the new password in the Password field that we created and click Save.
The User’s password will be changed and an email with the new security token will be emailed to the User.
Update: To send the new password to the user by email, the trigger will be:
trigger CPTsetPassword on User (before update) { List <String> toAddresses = New List <String>(); for (User u:Trigger.New) { User oldUser = Trigger.OldMap.get(u.id); If ((u.Password__c != null) && (oldUser.Password__c != u.Password__c)) { System.SetPassword(u.id,u.password__c); toAddresses.add(u.Email); //Uncomment below line to clear password field after reset //u.Password__c = null; //Sending the users new password by email Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); mail.setToAddresses(toAddresses); mail.setSubject('Salesforce Password Reset'); mail.setPlaintextBody('Your password was reset by the Administrator and the new Password is ' + u.Password__c); Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail}); } } }
Leave a Reply