This error occurs when you attempt to reassign a Salesforce user to a profile that is associated with a different User License type than the user's current license. Salesforce enforces a dependency between a user's Profile and their User License — a user can only be assigned to profiles that are valid for their license type. Attempting to change the ProfileId via Apex to a profile on a different license throws the following error:FIELD_INTEGRITY_EXCEPTION, You can only reassign this user to a profile of the current license.: [ProfileId]
This behavior is by design, because allowing cross-license profile assignment via code would create security risks.
Example that causes the error: Querying users with a Chatter license profile, then attempting to set their ProfileId to a Standard Platform User profile (which uses a different license type), and then performing an update DML operation.
list<user> users = [SELECT Id, firstname, lastname, IsActive, ProfileId, UserType FROM User where profileId in :[select id from Profile where name = '<chatter user profile>']]; // these users have different license, suppose "XYZ License"
Profile p = [select id from profile where name='Standard Platform User']; // And these users have different license, suppose "ABC License"
for(User u:users){
u.profileId= p.id;
}
update users;
Result : FIELD_INTEGRITY_EXCEPTION, You can only reassign this user to a profile of the current license.: [ProfileId].
Example that works: Querying users with a Standard User profile (Salesforce license) and updating their ProfileId to a Standard Platform User profile (also Salesforce license), because both profiles share the same license type.
list<user> users = [SELECT Id,firstname, lastname, IsActive,ProfileId,UserType FROM User where profileId in :[select id from Profile where name = 'Standard User']]; // these users have "salesforce License"
Profile p = [select id from profile where name='Standard Platform User'];// these users have "salesforce License"
for(User u:users){
u.profileId= p.id;
}
update users;
Result : updated successfully
This behavior is working as designed. A User's Profile is always dependent on their User License type, and direct ProfileId reassignment across license types is blocked in Salesforce for security reasons.
To change a user's profile to one associated with a different license type, use the following approach:
Query the users currently assigned to the source profile (the one with the old license type). Retrieve all fields required for the new user record.
Set IsActive = false on each user and perform an update DML operation. This deactivates the existing users.
Create new User records with all required fields (copied from the deactivated users) and set the ProfileId to the target profile (associated with the new license type). Insert the new user records.
Note: This workaround effectively replaces the user record. Ensure that all related records, permissions, and sharing rules are updated to reference the new User IDs after insertion.
list<user> users = [SELECT Id,firstname, lastname, IsActive,ProfileId,UserType FROM User where profileId in :[select id from Profile where name = 'portal']]; // these users have different license, suppose "XYZ License"
Profile p = [select id from profile where name='community']; // And these users have different license, suppose "ABC License"
for(User u:users){
u.isactive = false;
}
update users;
list<user> newUserList = new list<user>();
for(User u1:users){
user NewUser = new user();
NewUser.allrequiredFields = u1.allrequiredFields;
.
.
// put all required fields
newUserList.add(NewUser);
}
insert newUserList;
000386999

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.