Newer Version Available
Create a Custom Login Flow with Visualforce
Define the business process in an Apex controller of the Visualforce page. Salesforce doesn’t pass input variables to a Visualforce Page login flow, but you have access to user and login context. You must include one of these Apex methods.
- Auth.SessionManagement.finishLoginFlow() indicates that the login flow is done and redirects the user to the home page
- Auth.SessionManagement.finishLoginFlow(startURL) indicates that the login flow is done and redirects the user to a specific page.
The login flow runs in a restricted session. Calling a finishLoginFlow method removes the session restriction and gives users access to Salesforce or their community. You decide when or under what condition to call the method to remove the session restriction.
Here’s an example of a Visualforce Page login flow. The user clicks a button to invoke the finishLoginFlow method. Specify showHeader=”false” for the login flow to work correctly.
1<apex:page showHeader="false" controller="VFLoginFlowController">
2 <h1>You are in VF Login Flow</h1>
3 <apex:form >
4 <apex:commandButton action="{!FinishLoginFlowHome}" value="Finish and Go to Home"/>
5 <apex:commandButton action="{!FinishLoginFlowStartUrl}" value="Finish and Go to StartUrl"/>
6 </apex:form>
7</apex:page>Here’s an example of an Apex controller that defines the business process.
1public class VFLoginFlowController {
2
3 public PageReference FinishLoginFlowStartUrl() {
4 //do stuff
5
6 //finish the login flow and send you to the startUrl (account page in this case)
7 return Auth.SessionManagement.finishLoginFlow('/001');
8 }
9
10
11 public PageReference FinishLoginFlowHome() {
12 //do stuff
13
14 //finish the login flow and send you the default homepage
15 return Auth.SessionManagement.finishLoginFlow();
16 }
17}Give each profile that you want to associate with this Visualforce Page access.
- From Setup, enter Visualforce in the Quick Find box, then select Visualforce Page.
- Next to the Visualforce page that you want to use, click Security.
- From the list of available profiles, add the profiles that you want to associate with this login flow.
- From Setup, designate the Visualforce page as a login flow, and connect the profiles to it. See Set Up a Login Flow and Connect to Profiles.