You need to sign in to do that
Don't have an account?

Portal user creation using apex
I am working on a requirement to automate portal user creation based on user requests and sync it to downstream system real time. I have a problem creating contact and user in Same transaction due to setup non setup object. I cannot create user in a future method since I need to display the status of user creation on vf page for user. Appreciate if anyone has a workaround for this issue
<!---VF code snippet-->
<apex:commandButton value="Save" action="{!createContact}" onComplete="createUser();"/>
<apex:actionFunction name="createUser" action="{!createUserController}"/>
In the above snippet, createContact is your controller method that creates a Contact when "Save" button is clicked. Once the transaction is completed, the createUser(); JS function is called which subsequently calls the action method in your controller createUserController.
This is how you can bifurcate the process in 2 transactions. Once you have this ready, you may want to add some validations like caling the createUserController method only when the contact was created successfully.
All Answers
You can use future annotaion to solve this issue .
You can check the below link for more clarity .
https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_dml_non_mix_sobjects.htm
<!---VF code snippet-->
<apex:commandButton value="Save" action="{!createContact}" onComplete="createUser();"/>
<apex:actionFunction name="createUser" action="{!createUserController}"/>
In the above snippet, createContact is your controller method that creates a Contact when "Save" button is clicked. Once the transaction is completed, the createUser(); JS function is called which subsequently calls the action method in your controller createUserController.
This is how you can bifurcate the process in 2 transactions. Once you have this ready, you may want to add some validations like caling the createUserController method only when the contact was created successfully.