Sub topic 14
Deactivating Users and Releasing Licences
This chapter covers how to take a user out of service, what that does to licence capacity, and when to freeze a user instead. It assumes you can already create a user in Setup and check licence capacity with the SOQL queries from earlier chapters. You need the Manage Users permission to follow along.
Why users are deactivated, not deleted
Salesforce does not let you delete a user record. A user is referenced all over the org: as the owner of records, as the creator and last modifier on audit fields, in field history, in approval histories and in login history. Deleting the user would break those references and damage the audit trail.
Deactivation is the supported alternative. A deactivated user has the IsActive field set to false. The record stays in the org, and its name still appears on records the user created or owned.
Deactivation has these effects:
- The user can no longer log in.
- The user's licence is released, so
UsedLicensesdrops by one and the seat is available for another user. - The user's username stays reserved. You cannot reuse it for a new user, because usernames are unique across all Salesforce orgs.
- Existing records owned by the user stay owned by that user until you reassign them.
Deactivate versus freeze
Freezing is a lighter action. It blocks login but keeps the licence in use. Use the table to choose.
| Action | Blocks login | Releases user licence | Typical use |
|---|---|---|---|
| Freeze | Yes | No | Short-term lockout while you investigate, or while you remove dependencies before deactivating |
| Deactivate | Yes | Yes | Employee left, contractor finished, licence needed elsewhere |
Freezing is useful when deactivation is blocked. Some users cannot be deactivated straight away because they are referenced by something in the org. Freezing them stops access immediately while you clear the blockers. Freeze and unfreeze are available from the user's record in Setup, using the Freeze button, which sits next to the Edit button on the user detail page.
Deactivating a user in Setup
- From Setup, enter Users in the Quick Find box and select Users.
- Click the name of the user you want to deactivate.
- Click Edit.
- Clear the Active checkbox.
- Click Save.
- Confirm the warning message if one appears.
A faster route is the Users list. Open it, find the user, and select the checkbox beside the name. Then use the Deactivate option if your org shows one. Which controls appear depends on the org's user interface settings, so the single-user edit above is the most reliable path.
Deactivating several users at once
Salesforce lets you deactivate several users from a list view or with Data Loader. With Data Loader you run an update on the User object with a CSV that contains the user ID and the new value for IsActive.
Id,IsActive
<UserId1>,false
<UserId2>,falseReplace each <UserId> with the real 15 or 18 character user ID. You can get the IDs by exporting users with a query such as the one below.
SELECT Id, Name, Username, IsActive, LastLoginDate
FROM User
WHERE IsActive = true AND LastLoginDate < LAST_N_DAYS:90
ORDER BY LastLoginDateThis query lists active users who have not logged in for 90 days. Treat the result as a list of candidates, not a list to deactivate blindly. Integration users and service accounts may log in rarely and still be needed.
What can block deactivation
Salesforce stops you from deactivating a user in several situations. The error message names the cause, so read it before you retry.
| Blocker | Why it blocks | How to clear it |
|---|---|---|
| User is the default workflow user, or the default owner for a feature | Automation would have no valid owner | Change the default user in the relevant setup page, then deactivate |
| User is in a custom hierarchy field or an active approval process as an approver | The process would stall | Replace the approver, then deactivate |
| User is the only active user with a required permission, for example the last System Administrator | The org would lose administrative access | Assign the permission to another user first |
| User owns a Salesforce Knowledge article draft or a similar owned item that must have an active owner | The item needs an active owner | Reassign the item |
| User is a portal or community user with open dependencies | Related records need an active contact or owner | Review the related records, then retry |
Exact wording and the list of blockers vary by feature and release, so treat the table as a guide to the kinds of cause, not a complete list. If the error is unclear, freeze the user to stop access and then investigate.
Reassigning work before you deactivate
Deactivating a user does not move their records. A lead, case or opportunity owned by an inactive user stays visible to people who have access, but it may not receive routing or notifications, and reports grouped by owner will show the inactive name.
Before you deactivate, decide what should happen to:
- Records the user owns. Use Transfer Records from Setup, a list view mass transfer, or a Data Loader update of
OwnerId. - Items waiting for the user's approval.
- Scheduled reports and dashboards run by the user. A dashboard that runs as an inactive user stops refreshing.
- Email alerts, assignment rules and queues that name the user.
- Reports or list views that are filtered by the user's name.
Transfer first, deactivate second. This order avoids a period when records have no active owner.
Confirming that the licence was released
After deactivation, run the capacity query from the earlier chapter and compare the number with your previous count.
SELECT Name, TotalLicenses, UsedLicenses
FROM UserLicense
ORDER BY NameUsedLicenses for the user's licence type should have dropped by one. For permission set licences, run the matching query.
SELECT MasterLabel, TotalLicenses, UsedLicenses
FROM PermissionSetLicense
ORDER BY MasterLabelIf the permission set licence count did not change, the user may still hold a PermissionSetLicenseAssign record. A deactivated user can keep these assignments, and they continue to use capacity. List the assignments for one user with this query.
SELECT Id, PermissionSetLicense.MasterLabel, AssigneeId
FROM PermissionSetLicenseAssign
WHERE AssigneeId = '<UserId>'Remove them from the user's detail page in Setup, under Permission Set License Assignments, or delete the records through Data Loader or Apex. Before a licence assignment can be removed, you must first remove any permission sets that depend on it. Otherwise Salesforce refuses the change.
Deactivating with Apex
You can deactivate users in code, for example in a scheduled clean-up job. One restriction matters. Updating a User record in the same transaction as a non-setup object such as an Account raises a mixed DML error. Keep user updates in their own transaction, or run them asynchronously.
List<User> candidates = [
SELECT Id, IsActive
FROM User
WHERE IsActive = true
AND LastLoginDate < LAST_N_DAYS:180
AND Profile.UserLicense.Name = 'Salesforce'
LIMIT 50
];
for (User u : candidates) {
u.IsActive = false;
}
Database.SaveResult[] results = Database.update(candidates, false);
for (Integer i = 0; i < results.size(); i++) {
if (!results[i].isSuccess()) {
System.debug('Could not deactivate ' + candidates[i].Id + ': '
+ results[i].getErrors()[0].getMessage());
}
}The false argument allows partial success. One blocked user does not roll back the others, and the loop reports each failure. Run this in a sandbox first and review the candidate list, because the query shown matches real people.
Reactivating a user
Reactivation reverses deactivation. Open the user, edit the record, and select Active. Reactivation needs a free licence of the right type, so it fails if capacity is exhausted. The user keeps the same username, profile and permission set assignments, but you should review them, since the access may no longer match the person's role.
If the user was frozen, click Unfreeze instead. No licence check is needed because the seat was never released.
Common mistakes
- Deactivating without transferring records. Owned records stay with the inactive user and cause reporting and routing gaps.
- Assuming a deactivated username is free. It remains reserved. Create the new account with a different username.
- Forgetting permission set licences. The user licence is back, but the add-on seat is still consumed.
- Deactivating integration users based on login date. A user that calls the API with a token may appear idle in the UI but is still needed.
- Freezing and leaving it. A frozen user still counts against capacity, so a long-term freeze wastes a seat.
Exercise
A manager asks you to free a Salesforce licence for a new hire. You deactivate the departing user, but the query on PermissionSetLicense still shows the same UsedLicenses for an add-on licence that the departing user held. What is the likely cause, and what do you do?
Show answer
The deactivated user still has a PermissionSetLicenseAssign record, and deactivation does not remove it, so the add-on licence stays in use. Query PermissionSetLicenseAssign for that user's ID, remove any permission sets that depend on the licence, then delete the assignment (in Setup, with Data Loader or with Apex). Re-run the PermissionSetLicense query to confirm UsedLicenses dropped.
Exercise
Why would you freeze a user before deactivating, and which licence count changes when you freeze?
Show answer
Freezing blocks login at once while you transfer records and replace approver or default-user references that block deactivation. No licence count changes, because a frozen user keeps the user licence. Only deactivation releases it.