function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Matt Brown 71Matt Brown 71 

INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY when setting IsPortalEnabled to False.

I am getting the following error when a submit button is clicked from a visual force page that triggers a method that disables a community user:

INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, insufficient access rights on cross-reference id: []

For some reference, here is the bit of code that triggers it
 
// ... User selected earlier, verified good selection, etc. 

users[0].IsActive = false; 
users[0].IsPortalEnabled = false; 

Database.DMLOptions options = new Database.DMLOptions(); 
updateUserResult = Database.update(users[0], options); 

if (updateUserResult.isSuccess()) { 
    // I do some other stuff, like create user 
} else { 
    // I output error here. (where I'm getting this error) 
} 

// ... Truncated

I do not get the error when I comment out the IsPortalEnabled line.  Now I have read that this can occur when you literally just don't have access, but I have full CRED access to all objects in our org. I have also read that this could be from referencing an Id which is invalid - but I'm not doing any of that, I'm literally just flipping a boolean here and getting this error.

Does anyone have some insight on things I can check to hunt down this issue?  It's also worth noting that I am able to "disable community user" from interface and when running the following in an anonymous execute:
 
List<User> users = [SELECT Id, Username, Profile.Name, Profile.Id, IsPortalEnabled, IsActive, ContactId, ProfileId FROM User WHERE ContactId = '<theContactId>']; 
users[0].IsPortalEnabled = false; 
users[0].IsActive = false; 
update users[0];
This above not give me an error in anonymous window in dev console.

Any ideas?  I have been researching solutions to this for a few days now and have come up empty.