Sub topic 3
Checking how many licences you have left
This chapter assumes you can open Setup in a Salesforce org, you know what an object and a record are, and you have the Manage Users permission or an administrator profile. The SOQL sections assume basic query syntax. You do not need Apex for this chapter.
Before you create a user, confirm that a licence is free for that user. If none is free, the save fails and you lose time diagnosing it. This chapter shows where to read licence capacity, how to query it, and how to interpret the numbers.
Why capacity matters before you create a user
Every active user consumes one user licence. A user licence belongs to a licence type, such as Salesforce or Salesforce Platform. Your org buys a fixed number of each type. When all licences of a type are in use, you cannot create another active user on a profile that needs that type.
Permission set licences work the same way. They are a separate pool, and you check them before you assign a permission set that requires one.
There are three places where capacity can run out:
- The user licence behind the profile you want to use.
- A permission set licence behind a permission set you want to assign.
- A feature licence, such as Marketing User or Knowledge User, which is a checkbox on the user record with its own limit.
The rest of the chapter covers each place in turn.
Reading capacity in Setup
The quickest check uses the Setup UI.
- Click the gear icon and choose Setup.
- In Quick Find, type Company Information and open it.
- Scroll to User Licenses.
The table lists each licence type with these columns:
| Column | Meaning |
|---|---|
| Name | The licence type, for example Salesforce or Salesforce Platform. |
| Status | Whether the licence is active in the org. |
| Total Licenses | How many licences the org has purchased. |
| Used Licenses | How many are assigned to active users. |
| Remaining Licenses | Total minus used. |
| Expiration Date | When the licence ends, if it has a term. |
On the same page, Permission Set Licenses and Feature Licenses have their own tables with the same kind of columns. Read all three before a large onboarding.
Check the Status and Expiration Date columns as well as the counts. A licence that has expired shows capacity on paper but gives you nothing to assign.
Querying capacity with SOQL
The Setup page is fine for one-off checks. A query is better when you want to repeat the check, sort it, or compare it with a count of users. You can run these queries in the Developer Console (Query Editor), in Salesforce Inspector, or from VS Code with the Salesforce extensions.
User licences
UserLicense is a standard object with one row per licence type in your org.
SELECT Name, TotalLicenses, UsedLicenses
FROM UserLicense
ORDER BY NameThe result looks like this in a typical developer org:
| Name | TotalLicenses | UsedLicenses |
|---|---|---|
| Salesforce | 2 | 2 |
| Salesforce Platform | 3 | 1 |
| Identity | 10 | 0 |
In this example you cannot create another user on a profile that uses the Salesforce licence, because 2 of 2 are used. You can still create users on Salesforce Platform profiles, because 2 licences are free.
UserLicense has no field for remaining licences. You calculate it as TotalLicenses - UsedLicenses. You can add the status to the query to filter out licences that are not active:
SELECT Name, LicenseDefinitionKey, Status, TotalLicenses, UsedLicenses
FROM UserLicense
WHERE Status = 'Active'
ORDER BY NameLicenseDefinitionKey is a stable identifier for the licence type, for example SFDC for the Salesforce licence. Use it in scripts, because the display name can change.
Permission set licences
Permission set licences are in a different object, PermissionSetLicense.
SELECT MasterLabel, TotalLicenses, UsedLicenses
FROM PermissionSetLicense
ORDER BY MasterLabelUse MasterLabel for the display name here. This object has no Name field that you want for display, and the label is the one you see in Setup. As with user licences, remaining capacity is TotalLicenses - UsedLicenses.
Permission set licences also have an ExpirationDate and a Status. Add them when you want to confirm that a licence is still valid.
Which profiles use which licence
Capacity is only useful if you know which profile draws from which pool. Each profile points to exactly one user licence. This query lists the pairing:
SELECT Name, UserLicense.Name
FROM Profile
ORDER BY UserLicense.Name, NameUserLicense.Name is a relationship field, so the query reads the licence name through the profile. Run this query together with the capacity query. If Salesforce is full, every profile that lists Salesforce is unavailable for new active users.
Counting current users per licence
You can cross-check UsedLicenses against the real user count.
SELECT Profile.UserLicense.Name licence, COUNT(Id) activeUsers
FROM User
WHERE IsActive = true
GROUP BY Profile.UserLicense.Name
ORDER BY Profile.UserLicense.NameThe counts should match UsedLicenses for each licence. Small differences can appear for licence types that are consumed in other ways, as described in the next section.
How to read the numbers
The counts are simple, but a few rules affect how you interpret them.
Only active users consume a licence
UsedLicenses counts active users. A deactivated user releases the licence at once. A frozen user does not: freezing blocks login but the user stays active, so the licence stays in use. The chapter on deactivating and freezing users covers this in detail.
Counts can lag a little
Some licence types update their used count asynchronously. If you deactivate a user and the count does not change right away, wait a short time and run the query again before you assume something is wrong.
Not every licence consumer is a user
Some licence types are consumed by objects other than internal users. For example, Experience Cloud licences may count external users, or for some licence types, logins or members. For those types, comparing UsedLicenses with a user count is not exact. Use the licence table in Setup as the source of truth.
A licence can be full even when users look few
Inactive users do not count, but integration users and other automation users do, if they are active. In a small org, these can use up the last licences without anyone noticing. If used licences look higher than expected, list active users for that licence and look for service accounts.
SELECT Name, Username, Profile.Name, LastLoginDate
FROM User
WHERE IsActive = true AND Profile.UserLicense.Name = 'Salesforce'
ORDER BY LastLoginDate ASC NULLS FIRSTUsers with no login or an old LastLoginDate appear first. They are the best candidates to review for deactivation, and the decision belongs to the business owner, not to you alone.
Working out whether you can create a batch
For a bulk load you need more than a yes or no answer. Compare the number of new users per licence type with the remaining capacity for that type.
| Licence type | Remaining | New users planned | Result |
|---|---|---|---|
| Salesforce | 2 | 5 | Short by 3. Free licences or buy more first. |
| Salesforce Platform | 2 | 2 | Exactly enough. No spare capacity left. |
| Identity | 10 | 4 | Enough, with 6 to spare. |
Do this per licence type, not as one org-wide total. A surplus in one type cannot cover a shortage in another, because a profile is tied to one licence type.
Also leave some room. If the last licence goes to a new hire, you have none for an urgent contractor or a replacement integration user.
Common mistakes
- Reading only the total. A large
TotalLicensesvalue means nothing ifUsedLicensesequals it. - Adding up different licence types. Capacity is per type. A profile uses one type only.
- Forgetting permission set licences. The user saves, but the later permission set assignment fails because that pool is full.
- Assuming a frozen user is free. Frozen users still use a licence.
- Ignoring expiry. Check the expiration date on trial or term licences.
Summary
- Capacity lives in three pools: user licences, permission set licences and feature licences.
- Read it in Setup under Company Information, or query
UserLicenseandPermissionSetLicense. - Remaining capacity is
TotalLicenses - UsedLicenses, per licence type. - Only active users use a licence, and frozen users are still active.
- Check capacity per type before you create users singly or in bulk.
Exercise
Your UserLicense query shows Salesforce with TotalLicenses 25 and UsedLicenses 25, and Salesforce Platform with TotalLicenses 10 and UsedLicenses 6. You need to create 3 users whose profiles use the Salesforce licence. A colleague says there are 4 free licences, so it is fine. Is the colleague right? What can you do?
Show answer
The colleague is wrong. Capacity is per licence type, and the 4 free licences are Salesforce Platform licences, which the Salesforce profiles cannot use. The Salesforce pool has 0 remaining. You can deactivate users who no longer need access (frozen users do not release a licence), buy more Salesforce licences, or, if the new users only need Platform-level access, use a Salesforce Platform profile instead.
Exercise
Write a SOQL query that returns the name and remaining count for permission set licences. Which part cannot be done in the query itself, and how do you handle it?
Show answer
Use SELECT MasterLabel, TotalLicenses, UsedLicenses FROM PermissionSetLicense ORDER BY MasterLabel. SOQL cannot compute TotalLicenses - UsedLicenses in the SELECT list, so you subtract the two values yourself in the result grid, a spreadsheet or code.