+ Start a Discussion

how do i query userlicense name from user object?

Hi all, how do i query userlicense name from user object?i need to list out the users name based on the user license (ex:Userlicense ='Salesforce') .pls provide with suitable example asap Thanks

I don't think you can do it in a single query, or well .. I can't at least.


You can get to it by code though, wrote some code to collect and spit users by userlicense, didn't test it , or put code to out put a result, but I hope you get the Idea. Probably can be done better optimized too.



Map<id,string>  lic_names = new map<id,string>(); //in case you want to look up the license name by id
for(userlicense ul:[select id, name from userlicense]){

//maps profileId, licenseID 
Map<Id,ID>  prof_lic_map  = new map<id,id>();
for(profile p:[select Id, userlicenseId from profile]){

//keep users / userlicense
map<id, list<user>> userList = new map<id,list<user>>();

for(User u:[select id,name, profileId from user]){
id licId = prof_lic_map.get(u.profileId);

   if( !userList.containsKey(licId)){
     userList.put(licId, new list<user>());





Jia HuJia Hu
try this,

List<AggregateResult> arlist = [Select Username uname, UserType utype From User Group By UserType, Username ];
for(AggregateResult ar : arlist) {
System.debug(' --------------- UserType: ' + ar.get('utype') + ' Username: ' + ar.get('uname') );
Christy Lv 3Christy Lv 3
select id, Profile.UserLicense.name
from User
vineel ragulavineel ragula
Yes, Profile.UserLicense.name it worked for me. Thanks @Christy Lv3
Juan VictorianoJuan Victoriano
Profile.UserLicense.name for me returns [object Object] 

Do you know how to make it return the license name, I'm trying to get it to return 'Salesforce' or 'Salesforce Platform'

@Juan Victoriano are you using Developer Console?
If yes, you should switch to Workbench (https://workbench.developerforce.com/), Maven Tools for Salesforce (https://chrome.google.com/webstore/detail/maven-tools-for-salesforc/kgookdjjmmekebgdecakmblghjgiaoem?hl=en) or any other tool that you can use to run SOQL queries
Aaron King 14Aaron King 14
select id, Name, ProfileId, Profile.UserLicense.name from user