1

I need to get users list which is group by the Salesforce licence. I need to get Permission set licences as well. Is there any way to do this?

2
  • 1
    please have a look at this post, looks similar to your. Dec 13, 2018 at 4:58
  • 1
    Also refer PermissionSetLicenseAssign and PermissionSetLicense sobjects
    – Reshma
    Dec 13, 2018 at 5:45

1 Answer 1

2

You can collect the users based on the License type, please refer the below code to collect a map of LicenseId to List of Users (can collect based on License Name as well).

Map<String, List<User>> mapLicenseToLstUser = new Map<String, List<User>>();
Map<Id, List<User>> mapLicenseIdToLstUser = new Map<Id, List<User>>();

for(User objUser : [select Id, Profile.UserLicense.Name From User Where Profile.UserLicenseId != null]) {
  if(!mapLicenseToLstUser.containsKey(objUser.Profile.UserLicense.Name)) {
    mapLicenseToLstUser.put(objUser.Profile.UserLicense.Name, new List<User>());
  }
  mapLicenseToLstUser.get(objUser.Profile.UserLicense.Name).add(objUser);

  if(!mapLicenseIdToLstUser.containsKey(objUser.Profile.UserLicenseId)) {
    mapLicenseIdToLstUser.put(objUser.Profile.UserLicenseId, new List<User>());
  }
  mapLicenseIdToLstUser.get(objUser.Profile.UserLicenseId).add(objUser);
}
system.debug('=======mapLicenseToLstUser======'+mapLicenseToLstUser);
system.debug('=======mapLicenseIdToLstUser======'+mapLicenseIdToLstUser);

enter image description here

You must log in to answer this question.

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