+ Start a Discussion
matthew Gordonmatthew Gordon 

Update User preferences for specific profile on user Creation


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;
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
    for (User userInLoop : userList) {
            userInLoop.UserPermissionsSupportUser = true;

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.