+ Start a Discussion
MJ Kahn / OpFocusMJ Kahn / OpFocus 

Apex code to create a Community User but not send the welcome email

I have a VF page with a custom controller that creates a Customer Community User for a pre-existing Contact record. I'd like to have the Community refrain from sending its standard welcome message to the newly created User. I've added the following to my code, but it still sends the welcome message:
 
User user = new User();
// initialize the other user fields

Database.DMLOptions dmo = new Database.DMLOptions();
dmo.EmailHeader.triggerUserEmail = false;
dmo.EmailHeader.triggerOtherEmail = false;
dmo.EmailHeader.triggerAutoResponseEmail = false;
user.setOptions(dmo);

user insert;
Is there any way to get the Community to not send its standard welcome message to users who are created from this page? (I do want the Community to send the standard welcome message for users who are created from other pages.)
 
ShashankShashank (Salesforce Developers) 
Welcome emaails can only be disabled at a community-level and not the page-level. However, you can still change the email template: https://developer.salesforce.com/docs/atlas.en-us.salesforce_communities_implementation.meta/salesforce_communities_implementation/networks_customize_email.htm