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.
For more information on Login Pages, see Login Page Types.
- 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
SiteLoginwith 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
SiteLoginwith 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.