My requirement is when a user logged into customer portal using credentials-profile has to be changed when a action is called on button-click. At the time of login -profile is say 'abc'. I have called a future method onclick of a button to change the profile to say 'xyz'. I am able to change the useremail but not the profileID,it is showing the following error: FIELD_INTEGRITY_EXCEPTION, Cannot change profile for current user: Profile ID

My future method is as follows:

@future public static void updateuserAFL(id userId,id profileid){ User tempUser = [select id,name,Email,Username,Profileid from user where id=:userId ]; tempUser.ProfileId=profileid; tempUser.Email='test@mphasis.com'; update tempUser; }

Can anyone please help me how to change the profie of the logged in user..


Please have a look once on below link to update user profile using apex code.

update user profile through apex

Here we are doing a HttpCallout, which in result update user profile as admin mode.

public void callPublicSite(){

     String remoteURL = 'https://testing.force.com/ProfileUpdate?userId=' userId+'&profileId='+profileIdToUpdate;

     HttpRequest httpRequest = new HttpRequest();
     HttpResponse httpResponse = new Http().send(httpRequest);


//page name: ProfileUpdate

public void doProfileUpdate()
      String userId = ApexPages.currentPage().getParameters().get('userId');
      String profileId = ApexPages.currentPage().getParameters().get('profileId');
      update new User(Id=userId,ProfileId = profileId);
   Catch(Exception e)
     System.debug('::::user profile not update'+e);

Same type of question is asked in salesforce QA https://developer.salesforce.com/forums/ForumsMain?id=906F000000090mLIAQ The above link might help.

  • Shanker, could you please provide more information in your answer than to refer to another site ? At least a summary of the answer there is prefered, so that the answer and content is not dependant on data elsewhere. – Samuel De Rycke Apr 22 '14 at 9:31
  • Found a nice video on youtube which demonstrate a workaround for the problem. youtube.com/watch?v=a2fJWeJscps I will update my answer with details solution to the problem after i get back to home – Shanker Paudel Apr 22 '14 at 10:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.