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?

  • 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


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

  if(!mapLicenseIdToLstUser.containsKey(objUser.Profile.UserLicenseId)) {
    mapLicenseIdToLstUser.put(objUser.Profile.UserLicenseId, new List<User>());

enter image description here

You must log in to answer this question.

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