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
Travis Cooper 17Travis Cooper 17 

What permissions to allow Customer Community Plus User to update Username in Salesforce in Portal?

I need to allow the user to update their username in the portal. What permissions will the profile need in order to allow this change to occur?

At the moment I am getting a insufficient_access_on_cross_reference_entity error. In a trigger handler I am running the following code.

private void processUpdatedUserFields() {

        Id loggedUserId = UserInfo.getUserId();
        User currentUser = [SELECT Id, Name, Email FROM User WHERE Id =: loggedUserId];
        for (User newUser : (List<User>) Trigger.new) {
            User oldUser = (User) Trigger.oldMap.get(newUser.Id);
            if (loggedUserId == newUser.Id && newUser.Email != oldUser.Email) {
                system.debug(logginglevel.error, 'isUpdateable::: ' + Schema.sObjectType.User.fields.Username.isUpdateable());
                newUser.Username = newUser.Email;
            }
        }
        
    }

This is running beforeUpdate and used to run successfully.

Thank you.
PawanKumarPawanKumar
As per my understanding, This is not possible to do using code. Once user created cannot be updated their username. But you can update other details. The only workaround is you ask the user to raise a request in the portal that request is redirected to Admin to fulfil. As admin can change data manually and can reset the password if required.
Travis Cooper 17Travis Cooper 17
The users are currently able to change their username in production and have been for quite some time, however, at the moment in our QA environment this issue has crept in. I created a future method to get around this issue, and that is working.

What is the difference between the permissions that a future method uses and a without sharing class uses if any? Why would a future method work and not directly in the trigger?

 
mukesh guptamukesh gupta
Hi Travis,

I think your commuity user profile  not able to access user object sothat you can not update this.

for this solution you need set permisson Read and Write for user object in community user profile.

if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh


 
Travis Cooper 17Travis Cooper 17
When I log out the User.sObject.getDescribe(); for the object in the context of the user I get the following:

This should mean that the user has the correct Read/Write permissions on the user object, right?

get Describe:::
Schema.DescribeSObjectResult[getHasSubtypes=false;getIsSubtype=false;getKeyPrefix=005;getLabel=User;getLabelPlural=Users;getName=User;isAccessible=true;isCreateable=true;isCustom=false;isCustomSetting=false;isDeletable=false;isDeprecatedAndHidden=false;isFeedEnabled=true;isMergeable=false;isMruEnabled=true;isQueryable=true;isSearchable=true;isUndeletable=false;isUpdateable=true;]