Flow Tutorial 2 - Automatically Update SFDC Contact From Email

This tutorial includes a video and written guide to walk you through building an automation Flow from start to finish.


The Problem to Solve

You want to automatically update Salesforce contacts from information in an email.

Required Materials

To follow along with this tutorial, you will need:

Salesforce developer account (free) from: https://developer.salesforce.com/signup

Download: Demo Customer Contact Data to copy and paste into email.

For best results, use the Chrome browser


Video - Set Up: Enable IMAP and Set Up Salesforce

If you have enabled IMAP on your Gmail account but are still unable to setup a Connection in HeroFlow, you may need to "Allow Less Secure App Access" to your Gmail account. Follow this link and click on the toggle button to enable: https://myaccount.google.com/lesssecureapps

Video - Update Salesforce Contact from Email

Guide Outline

The steps to complete for this guide are as follows:

  1. Basics for Creating Automations.

  2. Set Up Salesforce Account and set up Hero_Flow app.

  3. Enable IMAP in Gmail.

  4. Create SFDC Connection.

  5. Create IMAP Connection.

  6. Create IMAP Input.

  7. Create SFDC Output.

  8. Prepare demo data in Salesforce and Email.

  9. Build Flow.

  10. Run Flow.

  11. Confirm Success. 

  12. Stop or Delete the Environment.

Basics for Creating Automations

To build an automation, complete the following steps:

  1. Define the input data and how to access it. In this case, example text from an IMAP-enabled email account.

  2. Define the expected output data. In this example, contact information in Salesforce.

  3. Create your automation Flow in our drag-and-drop interface (Flow_Studio) by connecting your input and output.

Set Up Salesforce

This example also uses a connector for Salesforce which requires you to set up a developer account.

Sign In

  1. Go to https://developer.salesforce.com/ and click Sign Up.

  2. You will receive a verification email prompting you to reset your password.

Setting up your Hero Flow App

  1. Log into your Salesforce account at https://login.salesforce.com

  2. After logging in, you are taken to the Salesforce home screen.

  3. In the menu on the left side of the screen, locate Platform Tools.

  4. Under Platform Tools, click Apps → App Manager. Next, in the top right corner, click New Connected App.

  5. Enter an App nameAPI name, and contact email.

    1. Note: Email address is used to confirm your identity by Salesforce.

  6. Check the box Enable OAuth Settings.

  7. Enter the callback URL for your Hero_Flow account.

    1. Copy and paste the exact URL of your Hero_Flow Cloud environment. Replace the tab name with oauth2 (e.g., xyzabc123.cloud.automationhero.ai/oauth2).

  8. Select the following four OAuth scopes permissions for Hero_Flow accessing your Salesforce account. 

    1. Full Access

    2. Access and manage your data

    3. Access your basic information

    4. Perform request on your behalf

  9. Click Save.

The Salesforce connected app needs up to 10 minutes for new changes to take effect on the server.

Finding your Consumer Key and Secret:

  1. From the Salesforce home screen, click on App Manager.

  2. Locate the App you created for Hero_Flow. From the drop-down menu on the right, select View.

  3. Under API (enabled OAuth Settings), your Consumer Key and Consumer Secret are displayed. 

Set Up Gmail

Hero_Flow has many prebuilt connectors included to create connections to your data. This example uses a connector for IMAP, which requires you to enable your email account with IMAP.

  1. Log in to Gmail.

  2. Click on gear icon and select Settings.

  3. Click tab Forwarding POP/IMAP.

  4. Click to activate Enable IMAP and Save Changes.

  5. If you have enabled IMAP on your Gmail account but are still unable to setup a Connection in HeroFlow, you may need to "Allow Less Secure App Access" to your Gmail account. Follow this link and click on the toggle button to enable:

Create a Connection to Salesforce Account in Hero_Flow

  1. Open Hero_Flow.

  2. Click Connections from the menu on the left.

  3. Click CREATE NEW CONNECTION.

  4. Give the Connection a name and select Salesforce from the drop-down list for Connection type.

  5. The Salesforce Connection details screen pops up with fields that need to be configured.
    In order to configure the fields, you must set your Salesforce account OAuth security to recognize Hero_Flow.

Finding your Customer key and secret in Salesforce

  1. From the Salesforce home screen, click on App Manager.

  2. Locate the App you created for Hero_Flow and from the drop-down menu on the right, select View.

  3. Under API (enabled OAuth Settings), your Customer Key and Customer Secret are displayed. 

In Hero_Flow Connection settings

  1. Enter the Salesforce Consumer Key and Consumer Secret.

  2. Once all detail fields have been configured. Click SIGN IN WITH SALESFORCE.

  3. Confirm the Salesforce account you are using and then click Allow to create the connection with Hero_Flow.

    1. Note: You might first receive an instruction from Salesforce to confirm your account with a verification code. This code can be found in your email, as entered in the Salesforce app.

  4. Click TEST CONNECTION. A confirmation message is displayed if the connection has been established with your Salesforce account.

  5. Click OK to finish saving the Connection in Hero_Flow.

Create Connection to IMAP

  1. Open Hero_Flow.

  2. Click Connections from the menu on the left.

  3. Click CREATE NEW CONNECTION.

  4. Give the Connection a name and select IMAP from the drop-down list for Connection type.

  5. The Email (IMAP) Connection details screen pops up with fields that need to be configured.

    In order to configure the fields, you might need to contact your email administrator.
    Enter your email, and

    • Host name: imap.gmail.com

    • Port number: 993

    • Protocol: IMAPS

    • Username: Your username

    • Password: Your password

  6. Click TEST CONNECTION. A confirmation message is displayed if the connection has been established with your email account.

  7. Click OK to finish saving the Connection in Hero_Flow.

Create Email Input

  1. Open Hero_Flow.

  2. Click Inputs from the menu on the left.

  3. Click CREATE NEW INPUT.

  4. Give the Input a name and select IMAP Connection from drop-down list of previously created Connections.

  5. Click Folders and select INBOX from drop-down list to bring in.

  6. Click OK.

Create Salesforce Output

  1. Open Hero_Flow.

  2. Click Output from the menu on the left.

  3. Click CREATE NEW OUTPUT.

  4. Give the Output a name and select Salesforce Connection from drop-down list of previously created Connections.

  5. In Write objects of type drop-down list, select Contact.

  6. Add five new fields to the Salesforce object mapping table:

    1. Click ADD FIELD, name it Email and leave the data type STRING.

    2. Click ADD FIELD, name it FirstName and leave the data type STRING.

    3. Click ADD FIELD, name it LastName and leave the data type STRING.

    4. Click ADD FIELD, name it Phone and leave the data type STRING.

    5. Click ADD FIELD, name it Id and leave the data type STRING.

  7. Click OK.

Prepare Demo Data in Salesforce and Email

1. Open Salesforce

2. Click the App Launcher and select Contacts

3. Click Plus Sign (+) and select New Contact, enter information and Save

4. Create two new contacts:

a. First Name: Thomas, Last Name: Riker, Email: tr@titan.com, Phone: 555-555-5555, Title: CTO

b. First Name: Annika, Last Name: Hansen, Email: ah@titan.com, Phone: 999-999-9999, Title: CEO

c. Note: These are the phone numbers which will be updated.

5. In Contacts, review you have correctly created the contacts.

6. Open Email.

7. Send two emails to yourself one with updated contact information for Thomas and one with updated contact information for Annika.

a. Body of text for first email: Name: Annika Hansen Email: ah@titan.com Phone: 617.557.4656

b. Body of text for second email: Name: Thomas Riker Email: tr@titan.com Phone: 212.555.1701

c. Note: The goal of this automation is to update the Salesforce contacts with these new numbers. This demo data is available in course materials.

Build Flow

  1. Open Hero_Flow.

  2. Click Flows from the menu on the left.

  3. Click CREATE NEW FLOW.

  4. Give the Flow a name and click Okay.

Add Input

  1. Click Add Input and select the previously created Input named Email.

Pull and Clean Phone Number Data

  1. Click the plus sign ( + ) and select the Function RegExtract.

    1. In the Argument drop-down list, select EMAIL_CONTENT (STRING).

    2. Name the Output field name, RegexPhone.

    3. Fill out the RegEx field with: Phone: [0-9]{3}[-. ][0-9]{3}[-. ][0-9]{4}

    4. Click OK.

  2. Click the plus sign ( + ) and select the Function Flatten.

    1. In the Argument drop-down list, select the previously created RegexPhone (List{String}).

    2. Name the Output field name, flatRegexPhone.

    3. Click OK.

  3. Click the plus sign ( + ) and select the Function ReplaceAll.

    1. In the Argument drop-down list, select the previously created flatRegexPhone (String).

    2. Name the Output field name, finalPhoneNumber.

    3. Fill in the RegEx field with Phone:

    4. Leave the Replacement field blank.

    5. Click OK.

Pull and Clean Email Data

  1. Click the plus sign ( + ) and select the Function RegExtract.

    1. In the Argument drop-down list, select EMAIL_CONTENT (STRING).

    2. Name the Output field name, RegexEmail.

    3. Fill out the RegEx field with: Email: [a-zA-Z]+@.+\.com

    4. Click OK.

  2. Click the plus sign ( + ) and select the Function Flatten.

    1. In the Argument drop-down list, select the previously created RegexEmail (List{String}).

    2. Name the Output field name, flatRegexEmail.

    3. Click OK.

  3. Click the plus sign ( + ) and select the Function ReplaceAll.

    1. In the Argument drop-down list, select the previously created flatRegexEmail (String).

    2. Name the Output field name, finalEmail.

    3. Fill in the RegEx field with Email:

    4. Leave the Replacement field blank.

    5. Click OK.

Data Enrichment with Salesforce Query

  1. Click the plus sign ( + ) and select the Function Salesforce Lookup.

    1. Click Add Argument Field and select finalEmail (STRING).

    2. Click Add Output Field and fill in three output fields:

      1. Type FirstName and select data type STRING.

      2. Type LastName and select data type STRING.

      3. Type Id and select data type STRING.

    3. In Connections drop-down list, select Salesforce.

    4. Fill in the SOQL query field with SELECT FirstName, LastName, Id FROM Contact WHERE email =:finalEmail

    5. Click OK.

Add Output

  1. Click Add Output and select previously created Output called Salesforce.

    1. Select finalEmail(String) from the drop-down list in the Input field associated with the Output field Email(STRING).

    2. Select Id(STRING) from the drop-down list in the Input field associated with the Output field Id(STRING).

    3. Select FirstName(STRING) from the drop-down list in the Input field associated with the Output field FirstName(STRING).

    4. Select LastName(STRING) from the drop-down list in the Input field associated with the Output field LastName(STRING).

    5. Select finalPhoneNumber(STRING) from the drop-down list in the Input field associated with the Output field Phone(STRING).

    6. Click OK.

2. Click Save

Run Flow

  1. First option: In Flow Studio, click RUN NOW.

  2. Second option: Navigate to Flows in menu on the left. Click gear icon next to the Flow, select Schedule, and then select Now from the drop-down list.

Confirm Success

  1. Navigate to Salesforce Contacts page and refresh page.

  2. Confirm the contact numbers have been changed to match the contact numbers in emails.

Stop or Delete the Environment 

Running an environment costs money by the hour. Reduce costs by stopping or deleting an environment you are not actively using.

  1. Navigate back to your cloud home screen.
  2. Click the settings icon next to the name of your environment.
  3. Choose Stop or Delete to stop or delete the environment.