Flow: Create Login Flow with Terms of Service

In the last article we've learned how to use variables to look for and update records. Today, we'll take a look at a unique type of flow in Salesforce - the login flow. As the name implies, it’s a flow that runs whenever the user logs in.

This type of flow is perfect when you need to update your users about company policy or make sure they agree to new terms of service before they can access the Salesforce organization.

For this, we’re going to create a Screen Flow in Salesforce and configure it as Login Flow. It's going to run each time the user logs in and display terms of service. Unless of course, the user has already acknowledged they had read and agreed to them.

Create Field on User Object

First of all, we’ll need to create a field that’s going to be responsible for informing us (and the system) whether a user has agreed to the new terms of service or not.

We will create this custom field on the User object. Let’s make it a checkbox and name it Terms of Service.

Build the Flow

Now, we can go to the flow builder and start building the actual flow. (See the documentation if you are new to Flows)

Go to Setup and create a new Screen Flow.

Before we drag any elements onto the canvas, let’s prepare a couple of resources that we’ll need later on.

User's Agreement to Terms of Service

Go to the manager tab and click New Resource. We’ll be creating a formula so choose this as the resource type. Pick boolean for the data type. Let’s call it “UsersAgreement”.

Use the “Insert a resource” search bar to look for the checkbox field we’ve created in the user object.

User's First Name

Next, we’ll create a formula that’s going to display the user's name. This will make our messages feel more personalized.

This will be a Formula resource as well, but with a Text data type. We’re going to look for a field containing the user’s first name.

User's ID

Now, for the last formula, we’re going to look for the user’s ID. We’ll need that piece of information to update correct records. This will be identical to the last formula resource, with text data type and a formula for User’s ID field.

All right, now that we have the formula variables ready let’s proceed with creating the actual flow.

Set Up the Decision Element - Has User Agreed to Terms of Service Already?

Our first step will be to check whether the user logging in to the system has already agreed to terms of service or not. We don’t want employees to be forced to agree to them each time they try to log in.

We’ll create a decision element that’s going to check for that.

Drag and drop the decision element on the canvas and click on it to configure it.

The only outcome we need to set up is when the user hasn't already agreed to terms of service. This means we need to look at the value in the checkbox we created and see if it’s not False.

We will use the first formula resource we’ve created for this. Check the image below to see how it should be configured.

Configure the Screen with Terms of Service

Next step will be creating the actual screen with terms of service. Let’s drag and drop the screen element onto the canvas.

We’ll use two display text components - one to create a welcome message and the other one to display terms of service.

Use the “Insert a resource” search bar to insert the formula with the user’s first name to personalize this message. The whole message will look like this:

Hello, {!UserFirstName} - Please read and accept terms of service before logging in to the system.

The third component should be a checkbox. This will enable users to acknowledge they read and agree to terms of service.

With our screen complete, let’s connect the decision element to it. Make sure the outcome is set to “No”.

The default outcome shouldn’t be connected to anything. This way users who have already agreed to terms of service won’t see the screen we’ve just created.

Set Up the Second Decision Element - User Agreed to Terms of Service?

Users logging in to the system have a choice - they can either click on the checkbox and agree to terms of service or leave it blank. That’s why we need to make sure that only those that actually checked that field can access Salesforce.

Let’s bring another decision element onto the canvas.

Like before, we only need to configure one outcome. Let’s see if they agreed to terms of service. We will need to look for the checkbox resource from the screen we’ve just configured and set it to be false - (!$GlobalConstant.False).

Update User Records

All users who fit our first outcome should be able to login without the need to see terms of service from now on, so let’s update the checkbox we created on the user object.

Drag and drop the “Update Records” element and configure it.

Pick: “Specify conditions to identify records, and set fields individually” and choose “User” as the object we’ll be updating.

We need to find specific users so pick “Conditions are Met” in the “Conditions Requirements” field.

We will use our UserID variable to find the right records. We’ll be looking for records that have an ID field equal to our UserID variable.

What's left is to update the right field, so find the Terms_of_Service field and pick (!$GlobalConstat.True) as the value. This will update the field to “True”.

Great, now all we need to do is to configure the other path and we’re done.

Configure the Error Screen

If some users decide they aren’t ok with the Terms of Service they might want to skip the checkbox. We need to make sure that those people will see an error screen and be forcefully logged out.

Let’s put another screen element onto the canvas. We’ll let those users know that they can’t log in unless they click the checkbox.

Not much here to configure. Just a simple message informing them what they need to do is enough.

Set Up the Assignment

Time for the last step. We need to ensure that users who didn’t agree to Terms of Service will be logged out.

For this we will use one of the Login Flow Default Variables - LoginFlow_ForceLogout.

Create a new Resource called LoginFlow_ForceLogout and set the data type to be Boolean.

For more information about Login Flow Default Variables in Salesforce click here.

Now, drag and drop the assignment element onto the canvas. In the assignment configuration pick the newly created variable and set it up so it equals (!$GlobalConstant.True).

Awesome! Our flow is ready, so let’s activate it. Here's how the process should look:

But before you go to your team to announce your new exciting automation, we need to configure one more thing.

Create the Login Flow

Let’s leave the flow builder. Go to Salesforce Setup and type “Login Flows” in the search bar.

Here, we’ll create the actual login flow. Click on “New”.

There’s not much to configure here, but take a look at the User License and Profile fields. These two options might prove very useful if you need only specific users to see terms of service. It’s also recommended that you don’t set up any login flows for administrators.

And, of course, you need to pick the right flow.

And that’s all. Your login flow is ready. You can test it out and deploy to production.

Of course, this is just an example. Login flows are powerful automations that can be used in a variety of ways. If you have any questions be sure to let us know!