+ Start a Discussion
Abhijit Shrikhande 10Abhijit Shrikhande 10 

Community User Creation - How can I stop emails from going out to my customers?

I have the following process setup in my sandbox environment.

1) Read Data From Local Sqlserver
2) Call Apex Rest Class
3) Create Contacts.
4) Create community Users from the contacts.

Currently I am reluctant to run the 4th step in the process as I don't want emails going out to these contacts upon user creation. How can I stop that from happening? I don't want to stop all outgoing emails from the sandbox, but is there some setting that will not send emails when a user gets created?
Best Answer chosen by Abhijit Shrikhande 10
Abhijit Shrikhande 10Abhijit Shrikhande 10
Ok. I found that there are two things that I needed to do.
1> Turn off the "SEND WELCOME EMAIL" as suggested by Andy Boettcher in the above post.
2> Make a change to the user creation apex code.
 
User u2 = new User(contactId=con.Id,
                    username=con.Email,
                    firstname=con.FirstName,
                    lastname=con.LastName,
                    email=con.Email,
                    communityNickname = con.LastName + '_',
                    alias = string.valueof(con.FirstName.substring(0,1) + con.LastName.substring(0,1)),
                    profileid = PROFILE_ID_FOR_COMMUNITY_USER,
                    emailencodingkey='UTF-8',
                    languagelocalekey='en_US',
                    localesidkey='en_US',
                    timezonesidkey='America/Los_Angeles');
Database.DMLOptions dlo = new Database.DMLOptions();
dlo.EmailHeader.triggerUserEmail= false;
Database.saveresult sr = Database.insert(u2,dlo);

 

All Answers

Andy BoettcherAndy Boettcher
You can try unchecking the "Send Welcome Email" checkbox in the community setup (Administration / Emails) but you cannot stop ALL emails.  Give this a try in your sandbox and see if it works.
Abhijit Shrikhande 10Abhijit Shrikhande 10
I think that might work, but there is another checkbox "Generate New Password and Notify User" on the user creation page that is set to yes.
Abhijit Shrikhande 10Abhijit Shrikhande 10
Ok. I found that there are two things that I needed to do.
1> Turn off the "SEND WELCOME EMAIL" as suggested by Andy Boettcher in the above post.
2> Make a change to the user creation apex code.
 
User u2 = new User(contactId=con.Id,
                    username=con.Email,
                    firstname=con.FirstName,
                    lastname=con.LastName,
                    email=con.Email,
                    communityNickname = con.LastName + '_',
                    alias = string.valueof(con.FirstName.substring(0,1) + con.LastName.substring(0,1)),
                    profileid = PROFILE_ID_FOR_COMMUNITY_USER,
                    emailencodingkey='UTF-8',
                    languagelocalekey='en_US',
                    localesidkey='en_US',
                    timezonesidkey='America/Los_Angeles');
Database.DMLOptions dlo = new Database.DMLOptions();
dlo.EmailHeader.triggerUserEmail= false;
Database.saveresult sr = Database.insert(u2,dlo);

 
This was selected as the best answer