Using Visual Workflow to Update User Email Addresses

Visual Flow Email Update


I recently had a need to update Salesforce username and email addresses due to a change in the email domain. There were over 100 user accounts affected by the change and it really only made sense to do a mass-update using Data Loader.  The process for mass updating the User accounts only requires a few steps:

  1. Export User Id, Username, and Email address values to CSV using Data Loader.
  2. Update Username and Email address values in the CSV file.
  3. Use Data Loader to update the User records with new values from CSV file.

It is important to note that changing user email addresses will trigger the delivery of a confirmation email message to the new address.  This confirmation message instructs the user to click a link the body of the message to authorize the change.  Once the user clicks the link, the user record is updated to the new email address and the update process is complete. If the user does not verify the address change then the user email address will remain as the original value.

The Problem

Having previously made similar changes, I expected that most users would find the verification message and click the link to confirm the change. Experience taught me that there would be a few users who would overlook the message or encounter some other issue that would prevent them from changing their address.  

After talking it through with a co-worker, (Thanks Ben!) we set out to make an automated solution that would aid the stragglers with updating their Salesforce email address.  The basic goals were as follows:

  1. Check the email address of each user at the start of the process to decide if it contained the old domain name.
  2. Provide a message to users that informed them of the need to update their email address.
  3. Provide a method to automatically change the email address to the new value.
  4. Trigger delivery of the email change verification message.
  5. Remind the user to click the link in the verification email message.

Building the Solution

The Visual Workflow tool provides all the features necessary to build a solution that addresses this challenge.  For a primer on the features available in this tool, check out the Process Automation module in Trailhead.  This module will give you a good look at the features available by walking you through the process of building your first flow.  With that said, let’s jump in and build a flow to help users with changing their email address.

Create the flow – From Setup, navigate to Process Automation > Flows. Click the “New” button from the Flow page to launch the Flow Designer.

Define a formula to get the User Id. Interactive flows run in the context of the user and, using Formula resources, the flow can get access to user-specific values.  Navigate to the Resource tab in the Flow Designer and double-click the “Formula” item. Set the values for the Formula as follows:

Unique Name: fCurrentUserId
Description: User Id value of user executing the flow.
Value Data Type: Text
Formula Value: {!$User.Id}

Define a formula to get the current email address. Add another Formula to get the email address of the user executing the flow.

Unique Name: fCurrentUserEmailAddress
Description: Email address of current user.
Value Data Type: Text
Formula Value: {!$User.Email}

Define a formula to set the new email address. The user’s new email address will be in the format of  Add a formula field to the flow to automatically generate this value.

Unique Name: fUserNewEmailAddress
Description:  Email address for user in the new domain.
Value Data Type: Text
Formula Value: {!$User.FirstName} + “.” + {!$User.LastName} + “”

Add a decision element to the flow to check the user email address. Switch to the ‘Palette’ tab and drag a decision element into the canvas.  Name the item ‘Email Change Required’ and let the system automatically set the unique name field. In the ‘Outcomes’ section, set the name field to ‘Yes’ and set the Resource, Operator, and Values fields as below.

Resource: {!fCurrentUserEmailAddress}

Operator: Contains


This will cause the decision element to check if the current user email address has the old domain name.

Add a screen element to the canvas. Drag a screen element on to the canvas and assign it the name ‘Email Update Notice’.  Select a ‘Display Text’ output field and add it to the screen.

Set the name to: EmailUpdateNoticeText

Add text to the field to let the user know that their email address needs updating. In this example, I include a preview of the new email address as well as information informing the user to click the link in the verification email.

Add a Record Update element to the flow.  Drag a record update element to the canvas and assign it the name Update User Email Address.  This element will find the current User record and update the email address to the new value.  Use the following values to specify the object and record that to be updated.
Update: User
Criteria field: Id 
Operator: Equals
Value: {!fCurrentUserEmailAddress}

In the ‘Update record fields with variable, constant, input, or other values’:

Field: Email
Value: {!fUserNewEmailAddress}

If there were other user specific fields being updated, you would use the ‘Add Row’ feature and define the field and new value.  As we are only updating the email address, just click ‘OK’ to save the element.


Set the starting element.

With all of the elements defined, the flow now needs a starting point. Click the Decision element and hover over the top right corner until you see the green circle with the down arrow.  Once visible, click this icon to set the decision element as the starting element of the flow.


Link the Decision to the Screen element.  

Now click and hold the diamond at the bottom of this element and drag a line to the screen element.  Once over the screen element, release the mouse button.  A pop-up will appear with a list of the default and editable outcomes defined in the decision element.  Select the ‘Yes‘ option from the list and press ‘OK‘.
This will make sure that, when the user email address has the old domain name, the flow advances to the screen element.
Link the Screen to the Record Update element.

All that is left here is to link the screen element to the record update. Just like with the Decision element, click and hold the diamond under the screen element and drag the line to the record update element.

Save and Activate the flow. With all the necessary pieces added and linked all that is left to do is to save and activate the flow.

A brief summary of what this flow will do when triggered.

The flow starts with the decision element where it checks if the user’s email address contains the old domain name. If the email address has the old domain name then it will advance to the screen element. The screen element will tell the user that their Salesforce email address will be changed to the new value. Any other information added to the text box in the screen element will also be shown to the user at that time. When the user presses ‘next’ on the screen element, the flow advances to then update record element.  This element locates the user record and updates the email address with the value from the fNewUserEmailAddress formula. The flow terminates after the record update step completes. This will trigger the automatic delivery of the email change verification message from Salesforce.

The flow will exit early if the email address does not contain the old domain name as we have not linked the ‘Default Outcome’ to any other elements. This ensures that only users who have not changed their address are impacted by the updates in the flow.

Defining a Login Flow

Using a login flow to trigger the newly create visual flow will make sure that a check of the user email address occurs each time the user logs into Salesforce.  To create a login flow, go to Setup and enter ‘Login Flows‘ into the quick find box and select the ‘Login Flows’ entry from the quick find results.  

Click ‘New’ to define the flow using the following values:

Name: Start Update Email Flow
Flow: Update_User_Email_Address
User License: Standard
Profile: Custom: Sales Profile


Create Update Email Login Flow

For demo purposes, I have assigned a login flow that will fire for users with the ‘Custom: Sales Profile’ profile. If building a similar solution, be sure to select the right license and profile value for your Org.

See it in action


Now that the login flow has been added for the ‘Custom: Sales Profile’ users, the visual flow will fire after a successful login but before the user is shown the home page.  This will happen for users of both Classic and Lightning Experience.  If the user email address has been updated then the flow exits and the user will be directed to their standard home page.  If the address has the old domain name then the screen element is displayed and the user must press ‘Next’ to continue.  As indicated above, this will cause the record update element to set the user’s email address value to the new domain and trigger the verification email message. Here is an example of what the user would see when they login.


Login Flow Example