Loading
Salesforce now sends email only from verified domains. Read More
Identify Your Users and Manage Access
Table of Contents
Select Filters

          No results
          No results
          Here are some search tips

          Check the spelling of your keywords.
          Use more general search terms.
          Select fewer filters to broaden your search.

          Search all of Salesforce Help
          Create a Custom Login Flow with Visualforce

          Create a Custom Login Flow with Visualforce

          Use Visualforce and an Apex controller to create a custom login flow programmatically. With Visualforce, you have complete control over how your login page looks, behaves, and directs users after they complete the flow. You can design your login page from scratch and control every pixel of the page.

          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 can access user and login context. 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 Experience Cloud site. 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.

          <apex:page showHeader="false" controller="VFLoginFlowController">
            <h1>You are in VF Login Flow</h1>
            <apex:form >
              <apex:commandButton action="{!FinishLoginFlowHome}" value="Finish and Go to Home"/>
              <apex:commandButton action="{!FinishLoginFlowStartUrl}" value="Finish and Go to StartUrl"/>
            </apex:form>
          </apex:page>

          Here’s an example of an Apex controller that defines the business process.

          public class VFLoginFlowController {
          
              public PageReference FinishLoginFlowStartUrl() {
                  //do stuff
                  
                  //finish the login flow and send you to the startUrl (account page in this case)
                  return Auth.SessionManagement.finishLoginFlow('/001');
              }
          
          
              public PageReference FinishLoginFlowHome() {
                  //do stuff
                  
                  //finish the login flow and send you the default homepage
                  return Auth.SessionManagement.finishLoginFlow();
              }
          }
          

          Give access to each profile that you want to associate with this Visualforce Page.

          1. From Setup, enter Visualforce in the Quick Find box, then select Visualforce Page.
          2. Next to the Visualforce page that you want to use, click Security.
          3. From the list of available profiles, add the profiles that you want to associate with this login flow.
          4. 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.
           
          Loading
          Salesforce Help | Article