function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Demi DevDemi Dev 

Apex trigger that stops email from going out after a user record is created

So I found out that I cannot disable the automatic outgoing emails that is sent after a user record is created in Salesforce.
(We enables SSO in out environment, so it isn't necessary for the automatically generated email confirmation to be sent to users after they've been created in SF). Enetually, we'd like to sent out a custom email instead.

I was thinking to create a SF Apex rigger on the User object that somehow "deleted" the outbound email that is send after a user record is created.
Is this possible? Could someone assist with the code? I have very little experiece writing Apex triggers (but very eager to learn!)
Best Answer chosen by Demi Dev
Christan G 4Christan G 4

Hey Demi, thank you for your feedback. After researching more into your issue, I discovered that when a new user is created in Salesforce, there is a checkbox called "Generate new password and notify user immediately" located at the end of the page. If one unchecks this checkbox, the user should not receive an e-mail. This will have to be manually done each time.

I was trying to see if there was a way to automatically uncheck this checkbox and unfortunately, there doesn't seem to be a way to do this so far. Salesforce doesn't provide one the option to edit any of the fields on the User page layout and the API for the checkbox field doesn't appear in the user field in Setup which would be needed to write a trigger on it.

All Answers

Christan G 4Christan G 4
May I ask, what is causing the automatic outgoing email to occur (Ex. Workflow Rule, etc) and the reason why it couldn't be disabled?
Demi DevDemi Dev
It's the email that is sent out to new users once their user record is created.
The email is no longer needed because we have set up SSO.

I was hoping maybe I could set up a trigger on the outgoing email and just cancel the email. Or reroute the outgoing email from support@salesforce to a generic email address?
Christan G 4Christan G 4

Hey Demi, thank you for your feedback. After researching more into your issue, I discovered that when a new user is created in Salesforce, there is a checkbox called "Generate new password and notify user immediately" located at the end of the page. If one unchecks this checkbox, the user should not receive an e-mail. This will have to be manually done each time.

I was trying to see if there was a way to automatically uncheck this checkbox and unfortunately, there doesn't seem to be a way to do this so far. Salesforce doesn't provide one the option to edit any of the fields on the User page layout and the API for the checkbox field doesn't appear in the user field in Setup which would be needed to write a trigger on it.

This was selected as the best answer