Sub topic 13
Customizing the login process with login flows
This chapter assumes you can build a simple screen flow in Flow Builder and assign profiles in Setup. A login flow is a flow that runs right after a user authenticates and before they reach Salesforce. You can use it to add steps that password and MFA settings alone can't provide.
What a login flow does
A login flow is a screen flow that Salesforce starts once the user has proved their identity, including any MFA challenge. The user holds a session, but it stays restricted until the flow finishes. If the user closes the browser or abandons the flow, they are logged out.
Common uses:
- Showing terms of service that users must accept.
- Collecting missing data, such as a phone number.
- Prompting users to register a verification method.
- Sending users from risky locations to an extra check.
Login flows apply to interactive logins through the browser. They don't run for API logins, which the chapter on API logins and integrations covers.
How the flow fits in
Building and assigning one
- In Flow Builder, create a Screen Flow.
- Add the logic and screens you need, then save and activate the flow.
- In Setup, search for Login Flows and click New.
- Pick the flow, choose the Lightning Experience or Salesforce Classic type, and pick a Profile or User License to apply it to.
Salesforce passes login details into the flow if you create variables with matching names. Mark each one as available for input.
| Variable | Type | Contains |
|---|---|---|
| `LoginFlow_LoginType` | Text | How the user logged in, such as an application or SSO |
| `LoginFlow_IpAddress` | Text | The IP address of the login |
| `LoginFlow_UserAgent` | Text | The browser identifier string |
| `LoginFlow_Platform` | Text | The operating system |
| `LoginFlow_Application` | Text | The application used to log in |
| `LoginFlow_Community` | Text | The Experience Cloud site, if any |
| `LoginFlow_SessionLevel` | Text | The session security level |
A Decision element can then branch on these values. For example, if LoginFlow_IpAddress is outside your office ranges, show a screen that asks for extra confirmation.
You can check whether a flow behaves as expected by reviewing the logins it affected. This query lists recent logins with the application and IP address:
SELECT UserId, LoginTime, LoginType, SourceIp, Application, Status
FROM LoginHistory
WHERE LoginTime = LAST_N_DAYS:1
ORDER BY LoginTime DESC
LIMIT 100Common errors
- Locking users out. A flow with an error and no fault path can trap everyone assigned to it. Always connect fault paths to a screen that ends the flow.
- Assigning to your own profile first. Test with a profile that has only a few test users. Keep an administrator route that has no login flow.
- Using an inactive flow. Only active flows appear in the Login Flows picker.
- Expecting it to replace MFA. A login flow runs after authentication. It can add checks but doesn't replace verification.
- Overusing it. Every login pays the cost of the extra screens. Use a login flow only when a standard setting can't do the job.
Exercise
A login flow assigned to the Sales profile has a Get Records element that sometimes fails, and the flow has no fault path. What happens to affected users, and how do you fix it?
Show answer
Affected users can't finish logging in, because the flow stops with an error and the session stays restricted. Fix it by adding a fault path from the Get Records element to a screen that shows a message and ends the flow, then retest with a non-admin Sales user.