1

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());

    }
}

1 Answer 1

3

Each (normal) user can decide to not be included as BCC in his/her emails in user preferences. Just go to Setup or your Profile and look for Email -> Automatic BCC.

enter image description here

I believe the corresponding field in the database is User.EmailPreferencesAutoBcc

So your best bet would be to see if this field matches your user's preferences and maybe mass update the Portal users. Going forward - a workflow / process builder / trigger whenever new Community user is created?

Something like this?

trigger UserTrigger on User (before insert){
    Set<Id> portalProfiles = new Map<Id, Profile>([SELECT Id FROM Profile WHERE Name IN ('Partner Community User Custom')]).keyset();

    for(User u : trigger.new){
        if(portalProfiles.contains(u.ProfileId)){
            u.EmailPreferencesAutoBcc = false;
        }
    }
}

Make sure you have the Profile Name right. Actually it's probably bad idea to have hardcoded profile names... Run this query and decide if there's a better way:

SELECT Name, Profile.UserType, Profile.UserLicense.Name FROM User

(Profile object, UserLicense object)

1
  • Comments are not for extended discussion; this conversation has been moved to chat.
    – Adrian Larson
    Sep 22, 2017 at 17:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .