I want to know, current user limit i.e. how much I utilized and how much I have remaining.

I went through Limits class and UserInfo class, but I didn't find useful stuff. And even in OOTB, there is not specific count for user. There is only limits for Custom Fields, Workflow, relationships etc.

Anyone has idea, how to know the remaining user count or know the current org's user limit limit(which is customized mostly as per the requirement).

  • 2
    Do you mean the number of user licenses? Jul 28, 2016 at 3:57
  • yeah, total user licences count. So that I can query on available user object and deduct its row count from total count.
    – Ysr Shk
    Jul 28, 2016 at 3:58
  • 1
    I don't see a reason why you would do this through code ... go to setup -> Company information and you see full information on your license. Have a look on this similar question salesforce.stackexchange.com/questions/23413/… Jul 28, 2016 at 4:01
  • 1
    Well, I am developing a module, where we are automating user creation process through custom data. Hence, i will be needed this as a prevention cause.
    – Ysr Shk
    Jul 28, 2016 at 4:04
  • 1
    @Amr funny, that's pretty similar to the product team's response to this Idea. It doesn't seem like a crazy request to me.
    – Adrian Larson
    Jul 28, 2016 at 4:04

2 Answers 2


We have a UserLicense object in Salesforce, which stores all the license count information.

Link to documentation: UserLicense object.


select Id, Name, UsedLicenses, TotalLicenses, Status, MasterLabel, LicenseDefinitionKey from UserLicense

Apex code:

List<UserLicense> users = [select Id, Name, UsedLicenses, TotalLicenses, Status, MasterLabel, LicenseDefinitionKey from UserLicense];

for(UserLicense ul : users){
System.debug('Name: ' + ul.name);
System.debug('UsedLicenses: ' + ul.UsedLicenses);
System.debug('TotalLicenses: ' + ul.TotalLicenses);

There is an Idea asking for this feature, which seems to indicate what you want is not currently available on the platform.

Query License count in Apex

It would be great if we could query the license count in Apex. We have situations where we want to know if any licenses are available, and right now the only way we can tell is to look at the screens. This would be very helpful with writing any visual force pages that do user maintenance.

If you just want to find this information through the UI (not programmatically), you can go to Setup > Company Profile > Company Information.

You can handle the scenario where you have insufficient licenses in a catch block. You can use a rollback to prevent actual insert if you need to proactively gather this information.

Savepoint sp = Database.setSavepoint();
    insert mockUsers;
catch (DmlException dmx)
    for (Integer i = 0; i < dmx.getNumDml(); i++)
        if (dmx.getDmlType(i) == StatusCode.LICENSE_LIMIT_EXCEEDED)
            // did not have remaining license for mockUsers[i]
  • hmm yes we can catch that exception. However, I feel prevention is better than cure. And in my case, we have to enable "create user" form link, only if we have licences remaining. So this will not work. Btw, Thanks for your efforts.
    – Ysr Shk
    Jul 28, 2016 at 5:02
  • @Ysr You could roll back on success in that case.
    – Adrian Larson
    Jul 28, 2016 at 5:06
  • No, Because, the form itself will not be visible, so no data will be there, for the new creating user. The only alternate I can think with your approach is, create a user with dummy data. And when we have valid data and approval, then update it with that dummy user. And that is also erroneous as there are multiple requesters. It would be my last approach to get thing done.
    – Ysr Shk
    Jul 28, 2016 at 5:10
  • @YsrShk you could store the data in a Hierarchy Custom Setting and reference that in merge fields anywhere you want. You're making this a difficult question to answer.
    – Adrian Larson
    Jul 29, 2016 at 16:54

You must log in to answer this question.

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