Posts

Showing posts from February, 2016

How to change/update the profile of a User in Salesforce from apex code

It's my first blog writing, so ignore all the grammatical errors here :) A user profile update is not allowed through apex code generally and it through error  FIELD_INTEGRITY_EXCEPTION, Cannot change profile for current user: Profile ID. It can be achieve by Http callout. How to do this, its pretty simple. There are 2 way to do this: 1st:  If we have community or a site enabled in our sf org. It's  3-4 step process. Create a visualforce page and assign a controller to it. Make this page public through guest user permissions. Define an action in apex:page tag.  which will be called when ever this page executes In controller : action: write the code to update the profileId. It works. 1 2 3 4 5 6 7 8 9 10 public void callPublicSite (){ String remoteURL = ' https: //testing.force.com/ProfileUpdate?userId=' userId+'&profileId='+profileIdToUpdate; HttpRequest httpRequest = new HttpRequest(); httpRequest. setM