Currently, when our Portal users send any emails from Salesforce, they are automatically BCC on each email. While they are able to delete their email address out of the BCC field, we would like to turn the automatic BCC off for all of our Portal users (but not org-wide; so we don't want to go with the option of enabling the Compliance BCC Email). We just want to change this setting for Portal users. Is there a way to do that?
trigger UserTrigger on User (before insert) {
//This trigger is used to disable autobcc on email for portal users.
if(trigger.isBefore && trigger.isInsert) {
List<User> lstUsers = new List<User>();
Set<Id> setUserLicenceId = new Set<Id>();
List<Profile> lstPortalUserLicense = [SELECT Id,Name FROM Profile WHERE Name = 'Partner Community User Custom'];
System.debug('Debug Log for lstPortalUserLicense'+lstPortalUserLicense.size());
if(lstPortalUserLicense.size() >0){
for(Profile profile : lstPortalUserLicense) {
setUserLicenceId.add(profile.ID);
}
for(User u : trigger.new){
System.debug('Debug Log for userLicence '+u.ProfileID);
System.debug('Debug Log for email bcc preference'+u.EmailPreferencesAutoBcc);
if(setUserLicenceId.contains(u.ProfileID)) {
u.EmailPreferencesAutoBcc = false;
lstUsers.add(u);
}
}
}
System.debug('lstUsers size'+lstUsers.size());
}
}