2

Is there an easy way to do bulk assignment of licenses such as Knowledge User, Service Cloud User, etc., based on specified criteria? For example, assign Knowledge User license to all active users in a Public Group, or assign Service Cloud license to all active users of a certain UserType. I've seen one-off anonymous Apex scripts for assigning permission sets and am looking to do the same or similar for licenses. Thanks.

2

You can use dataloader to edit these permissions. You're looking for the UserPermissions* fields on the User table. Knowledge specifically is User.UserPermissionsKnowledgeUser and ServiceCloud is User.UserPermissionsSupportUser.

Extract the users you wish to edit via dataloader or workbench, then edit the csv to reflect those fields as true and use the update command in dataloader or workbench.

The easiest way to bulk load is to use the dataloader. I wouldn't use anon apex unless you have some complicated processing to do that cannot be done in a single query. To extract the users that are members of specific groups you can use a joined query like this:

select Id,UserPermissionsKnowledgeUser,UserPermissionsSupportUser from User where Id in (select UserOrGroupId from GroupMember where Group.Name in ('group1','group2'))

If you really want to make it anon apex though you can simply use something like this:

List<User> users = new List<User>();
for(User u : [select Id,UserPermissionsKnowledgeUser,UserPermissionsSupportUser from User where Id in (select UserOrGroupId from GroupMember where Group.DeveloperName in ('BAA_Issue_Submission','group2')) limit 10000]) {
  u.UserPermissionsKnowledgeUser = true;
  u.UserPermissionsSupportUser = true;
  users.add(u);
}
update users;

Note this can only process 10,000 records at a time due to execution governor limit on DML per execution, so it has a 10,000 limit on the query.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.