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
AshesAshes 

How to change own profile using Apex?

Hello,

we have a scenario here where we are providing a functionality to user to change his own profile through Apex visualforce page.

We are aware about Salesforce limitation to change own profile but stil is there any bypass for this?
Best Answer chosen by Ashes
MaxPowerForceMaxPowerForce
It isn't possible to do with a normal transaction, but here is an example of someone creatively using a REST callout to a force.com site to invoke the code:

https://www.youtube.com/watch?v=a2fJWeJscps

The underlying problem is that you cannot switch your own profile.  But, a web service callout through a force.com site runs as the site guest user and that user can switch a profile if it has appropriate permissions!

All Answers

MaxPowerForceMaxPowerForce
It isn't possible to do with a normal transaction, but here is an example of someone creatively using a REST callout to a force.com site to invoke the code:

https://www.youtube.com/watch?v=a2fJWeJscps

The underlying problem is that you cannot switch your own profile.  But, a web service callout through a force.com site runs as the site guest user and that user can switch a profile if it has appropriate permissions!
This was selected as the best answer
AshesAshes
Okay. Thats great. i will try to explore REST API Features. Thanks for your response.