Loading

'FIELD_INTEGRITY_EXCEPTION' error when ProfileId is updated via Apex

Udgivelsesdato: Jun 14, 2026
Beskrivelse

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 

Løsning

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.

Workaround: Deactivate and Re-create the User

To change a user's profile to one associated with a different license type, use the following approach:

Step 1: Query the Existing Users

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.

Step 2: Deactivate the Existing Users

Set IsActive = false on each user and perform an update DML operation. This deactivates the existing users.

Step 3: Create New User Records

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.

 
Sample code to workaround the issue
 
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;
Vidensartikelnummer

000386999

 
Indlæser
Salesforce Help | Article