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
matthew Gordonmatthew Gordon 

Update User preferences for specific profile on user Creation

Hi, 

I am trying to create a trigger when Users are created with a specific custom profile(there are multiple), they need to have the service cloud user flag checked. The trigger for enabling the flag on user creation was easy enough, but how do I limit to specific profiles? Is this possible?

trigger ForceServiceCloud on User (before insert) {
    for (User userInLoop : Trigger.new) {
        userInLoop.UserPermissionsSupportUser = true;
    }
}
CongnizentCongnizent
Please try this

trigger ForceServiceCloud on User (before insert) {
List<User> userList=[Select id, user.profile.name from user where id in : Trigger.new];
Set<String> profilelist=new  Set<String>();
//Add profile name
profilelist.add('p1');
profilelist.add('p2');
    for (User userInLoop : userList) {
        if(profilelist.contains(userInLoop.profile.name))
            userInLoop.UserPermissionsSupportUser = true;

    }
}
venkat-Dvenkat-D
Add list of profiles to custom label like p1;p2;p3 etc.
now on code use set<string> prfs = label.xyz.split(';');

then check for profile name from set. this way when you want to add or remove new profile, you can simply modify label than code.