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
Anu ManiappanAnu Maniappan 

How to stop the default email notifications for a particular User in salesforce through apex code

Hi All,

I am trying to stop the default email notifications for a particular User in salesforce through apex code.
Stopping default email notifications can be done manually by going to My Settings -> Email Settings and unchecking 'Receive emails' checkbox.
I need to achieve the same thing through Apex code. Please suggest how can this be done?

Thanks,
Anu
 
Best Answer chosen by Anu Maniappan
Anu ManiappanAnu Maniappan
For Community members NetworkMember object is used:
NetworkMember mem = [SELECT Id, PreferencesDisableAllFeedsEmail FROM NetworkMember WHERE MemberId = ''.....UserId...'];
mem.PreferencesDisableAllFeedsEmail = true;
update mem;

All Answers

Shaijan ThomasShaijan Thomas

UserPreferencesDisableAllFeedsEmail, check whether it will help
Anu ManiappanAnu Maniappan
UserPreferencesDisableAllFeedsEmail is used to disable all the Chatter related emails. But I need to stop all the email notifications to the user including the Private Messages notification emails.
Shaijan ThomasShaijan Thomas

Looks like 'ReceivesInfoEmails'. You can try this from user object. Not sure just for your reference. 
Anu ManiappanAnu Maniappan
'ReceivesInfoEmails' also is not stopping the Private messages notification emails.
Anu ManiappanAnu Maniappan
For Community members NetworkMember object is used:
NetworkMember mem = [SELECT Id, PreferencesDisableAllFeedsEmail FROM NetworkMember WHERE MemberId = ''.....UserId...'];
mem.PreferencesDisableAllFeedsEmail = true;
update mem;
This was selected as the best answer