+ Start a Discussion

SOQL query to fetch user records ( user license) based on department

Hi Team,
i need report of user records (user license) based on the department.
i.e need to know how many licenses are consumed by each department.

I have used below query but its working for only limit 100 becoz of Org limit..we have 1000+ departments. could you please help here?

SELECT COUNT(Id),Department from user where User_License_Name__c='Salesforce' group by Department limit 100

Thank You!
AnkaiahAnkaiah (Salesforce Developers) 
Hi VijayKumar,

You can generate a martix report on user object  based on User_License_Name__c field instead of quering.

Refer the below video, how to create matrix report.

If this information helps, Please mark it as best answer.

sanjita njitasanjita njita
The reason for the Kroger Customer Feedback Survey  (https://surveyfeedback.onl/www-krogerfeedback-com-survey/)also known as KrogerFeedback will be to offer better customer service to customers like you.
mukesh guptamukesh gupta
Hi Vijay,

Please follow below code:-
Map<Id,Profile> profileIds = new Map<id,profile>([SELECT Id,UserLicenseId FROM Profile where UserLicenseId in (SELECT Id FROM UserLicense where name ='Salesforce')]); 

List<user> standardProfileUsers = [select id from user where profileId in:profileIds.Keyset() group by Department limit 5000];

if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.