Salesforce provides an easy way to customize your login process using the Login
Discovery Page, which lets you implement passwordless login. However, if you want even more
control over your login process, you can modify the Apex login controllers and use customized
Visualforce pages.
Required Editions
Available in: Salesforce Classic and Lightning Experience
Available in: Enterprise, Performance, Unlimited, and
Developer Editions
User Permissions Needed
To create and edit Visualforce pages:
Customize Application
To edit Apex classes:
Author Apex
AND
Customize Application
You can use these steps to customize the login process for Default, Experience Builder,
and Visualforce Pages. If you're using the Login Discovery Page to implement passwordless login
programmatically, see Email or Phone Number Registration with
Passwordless Login.
From Setup, in the Quick Find box, enter Apex Classes, and then
select Apex Classes.
Next to CommunitiesLoginController, click
Edit.
Add the following code.
global PageReference forwardToCustomAuthPage() {
String startUrl = System.currentPageReference().getParameters().get('startURL');
return new PageReference(Site.getPathPrefix() + '/SiteLogin?startURL=' + EncodingUtil.urlEncode(startURL, 'UTF-8'));
}
If you created a custom login page, replace SiteLogin with the name of your Visualforce page.
Click Save.
Click Edit next to CommunitiesLandingController.
Add this code.
public PageReference forwardToCustomAuthPage() {
String startUrl = System.currentPageReference().getParameters().get('startURL');
return new PageReference(Site.getPathPrefix() + '/SiteLogin?startURL=' + EncodingUtil.urlEncode(startURL, 'UTF-8'));
}
If you created a custom login page, replace SiteLogin with the name of your Visualforce page.
Click Save.
From Setup, enter Visualforce Pages in the Quick Find box, then
select Visualforce Pages.
Click Edit next to CommunitiesLogin.
In the first line of code, add the following:
action="{!forwardToCustomAuthPage}"
Click Save.
Click Edit next to CommunitiesLanding.
In the first line of code, add the following:
action="{!forwardToCustomAuthPage}"
Click Save.
Did this article solve your issue?
Let us know so we can improve!
Loading
Salesforce Help | Article
Cookie Consent Manager
General Information
Required Cookies
Functional Cookies
Advertising Cookies
General Information
We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required Cookies
Always Active
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional Cookies
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising Cookies
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.