I want query the list of user with salesforce license
List<user> user11=[SELECT name from user limit 5000];
Didn't find how to do it in a single query, but this gives all users with a Salesforce user licence type. Important to know is that you have to query this through the profile.
Update: Peter's answer is better: He shows that you can infact get these results in a single query, which is prefered for performance and cleaner in code.
Take a look at the UserLicense object documentation. There is a field called
And one of the values:
If what you want is the Users with the Full CRM license than the following query can get them:
If what you want is the Users with a License Name of Salesforce than the following query can get them:
Those two queries return the same Users in my org. I suppose it's possible that the UserLicense.Name field could be changed at some point by Salesforce to be something else for the Full CRM License, whereas the UserLicense.LicenseDefinitionKey field is documented as the way to identify a User License.