I am working on a project to send custom WelcomeEmail to 400 new users in Salesforce, since Salesforce cannot send the verified email when creating users through data loader. (I don't prefer to send "ResetPassword" email to user as well, cuz it's not NewUsers friendly.)
**WelcomeEmail target functions:**
1. Appropriate Login Instructions
2. Include a Link that User can Set Password
I've developed an automated process to streamline this task. However, I'm facing a security problem, and I would appreciate your insights or suggestions for improvement.
Here's an overview of my current process:
Settings:
- Create NeedSetPW__c: New checkbox field on User Object
- Create SendCustomEmail__c: New checkbox field on User Object
- Create Apex Trigger:
trigger TestSetPassword on User (after update) {
for(User u : Trigger.new){
if(u.IsActive == true && u.NeedSetPW__c == true && u.SendCustomEmail__c == false){
system.setPassword(u.Id, 'Aa1234567s');
system.debug(u.id);
}
}
}
Here's the Steps
- Admins batch insert 400 users as inactive.
- Admins then update the users to active status and set NeedSetPW=true.
- An Apex trigger sets a predefined password when [IsActive==true && NeedSetPW__c==true && SendCustomEmail__c==false] .
- Admins batch update SendCustomEmail__c=true to trigger a flow.
- A Flow sends out an email when [IsActive==true && SendCustomEmail__c=true], and then resets NeedSetPW__c and SendCustomEmail__c to false.
- This process successfully sends out a welcome email with login instructions, and user will redirect to change password screen when using the predefined password to login.
The process uses fixed password for all new users, which is a security concern. Moreover, due to the limitations of Salesforce Lightning email templates, I can't include dynamically generated passwords in the email.
I'm considering ways to improve this process, especially in terms of security while maintaining a good user experience. Are there best practices or alternative approaches I should consider?
Thank you in advance for your valuable suggestions!