Start using IBM® App Connect on IBM Cloud without charge: create an event-driven flow from a template, to send an email via Gmail when a new lead is created in Salesforce; all in a few steps, in minutes.

Duration: When preparing this article, it took less than 3 minutes from start to finish – to create, start, and test the event-driven flow.

First, find or create everything you need

Duration: 3-10 minutes, depending on whether you have some accounts already.

Get accounts for App Connect, Gmail, and Salesforce…

  • Obtain an App Connect on IBM Cloud service. You can use an App Connect service that you already have or can sign up for App Connect from the IBM Cloud catalog.

    In this example, we use a new free App Connect – Lite plan service.

  • (If you haven’t already connected App Connect to your Gmail account) The name and password of your Gmail account.
  • (If you haven’t already connected App Connect to your Salesforce account) The name and password of your Salesforce account.

    If you want to create a free test account in Salesforce rather than use your business account, make sure that you register for a Developer account from this URL: https://developer.salesforce.com rather than a Trial account. If you connect to App Connect with a Trial account, the Salesforce events don’t work.

In the following steps, we started without App Connect already being connected to the Gmail and Salesforce accounts. We also chose to connect to Gmail and Salesforce as we edited the event-driven flow. (If App Connect was already connected to Gmail and Salesforce accounts, such as from an earlier flow or API, we would not have needed to connect again.)

Create an event-driven flow from a template

Duration: A few minutes

A quick and easy way to create an event-driven flow (or an API flow) is to use a pre-built template from the App Connect gallery of templates. If needed, you can then adapt the template to your needs.

Alternatively, if you don’t see a suitable template, you can import a flow definition file or create a new flow from scratch, perhaps following one of the App Connect tutorials for specific use cases.

Create the flow from the template…

This example uses the template “Send Gmail message to new Salesforce lead”. This template creates and sends an email via Gmail when a new lead is created in Salesforce. If there is no email provided for the lead then App Connect logs an error about the missing email.

To create the event-driven flow from the template, complete the following steps:

  1. Log in to App Connect.

    This displays the App Connect dashboard, which you’ll later use to manage your event-driven flow.

    This also shows other menu bar options, including Catalog to manage your use of the App Connect catalog of applications and APIs, and Templates to browse and select from the App Connect templates for event-driven flows and flows for APIs.

    App Connect dashboard without any flows or APIs. (Click image to view full size)

  2. Click the Templates menu bar option.
  3. In the search box, type send gmail, and then click the tile labelled “Send Gmail message to new Salesforce lead”.

    This displays a summary of the template, with brief instructions for how to use the template.

    App Connect templates, showing a template tile selected (Click image to view full size)

  4. Click Create flow.

    This creates an event-driven flow from the template, and opens the flow in the flow editor.

    App Connect flow editor, showing a new flow created from a template (Click image to view full size)

The flow is open in the flow editor, ready for us to validate and connect to the applications it uses.

Step 3: Explore and complete the event-driven flow

Duration: A few minutes

When you create a flow from a template, it is good practice to examine the flow to understand its actions. Also, you may need to connect applications used by the flow, or may choose to change an account used or otherwise adapt the flow to your needs.

Note that with a quick glance you can see any nodes that need attention, as they are marked with an exclamation mark in a red circle. If the node shows “Not connected“, this indicates that we need to connect to the application used, which we’ll do in the following steps.

Explore and complete the flow…

  1. Give the flow a name that is unique and meaningful to you.

    A flow created from a template is assigned the name of the template title; in this example, “Send Gmail message to new Salesforce lead”. If you want to change the flow name, click the name field and overtype with the name you want to use; for example: Welcome new Salesforce lead with Gmail message.

  2. Examine the event, Salesforce / New lead (Not connected), that will be used to trigger the flow.

    Click the event node. This displays the Connect button, for us to connect to the Salesforce account.

    1. Click Connect

      This displays the initial page of the Connect to Salesforce dialog.

      If required, you can use the Custom URL field to specify a special Salesforce environment (production or sandbox), or subdomain (with a personalized login page) that you want to connect to.

      If you want to learn more about using the Custom URL field for different ways to connect to Salesforce accounts, see How to use IBM App Connect with Salesforce.

      In this example, we left the Custom URL field blank, to connect to the standard (production) environment for our Salesforce Developer account. When connected, App Connect is automatically directed to use the generic production URL: https://login.salesforce.com.

    2. Click Connect
    3. To confirm that you have an appropriate Salesforce account, click Continue.

      This opens a Salesforce window for you to connect App Connect. Choose a username, and follow the Salesforce instructions to allow App Connect to access your Salesforce account.

      Salesforce window to allow App Connect access(Click image to view full size)

      When completed, the flow editor is updated with the event node now showing the account name used in App Connect for the Salesforce connection (for example, “Account 1”). If you want to change the account name shown, you must do so (on the Catalog / Applications page) before the connection is used by any running flow.

      Salesforce connection created (Click image to view full size)

  3. Examine the If node.

    In the flow editor, the view of the If node shows key information. You can see the If and else conditions, and the actions that will be taken.

    • If the Email property of the new Salesforce lead is not empty, then an email is sent by Gmail.
    • Else, the flow ends with the message “Email address was not provided for Lead ID = <Lead ID>”, where <Lead ID> is the value of the ID field from the new Salesforce lead.

    (Optional) To examine its logic more, click the If node . For each condition, this shows a field from the source application (Salesforce), an operation, and if appropriate, a value for the operation.

    If you want to learn more about using the If node, see Adding conditional logic to a flow.

  4. Examine the action, Gmail / Create message (Not connected), that will be used to send an email if the new Salesforce lead has an email address defined.

    Click the action node. This displays the Connect button, for us to connect to the Gmail account.

    1. Click Connect

      This displays the initial page of the Connect to Gmail dialog.

      Select your Google account, and follow the Salesforce instructions to allow App Connect to access your Google account.

      Google window to allow App Connect to access your Google account (Click image to view full size)

      When completed, the flow editor is updated with the action node now showing the account name used in App Connect for the Gmail connection (for example, “Account 1”). If you want to change the account name shown, you must do so before the connection is used by any running flow.

      Gmail / Create email action, showing To, Subject, and Body fields to be completed (Click image to view full size)

    2. Complete the Gmail fields needed to send the message:
      • *To: To send an email to the address defined in the new Salesforce lead, map the Email field from that lead:
        1. Click in the *To field.
        2. Start typing email and then pause briefly for App Connect to offer you choices based on “email”.

          Options offered by App Connect when typing "email" (Click image to view full size)

          Note, when you click in a target field (of Gmail / Create email), icons are shown next to the field: Icon to map a field from earlier node in a flow to enable you to map fields from Salesforce / New lead (any node earlier in the flow) or Icon to insert a function into a target field to insert JSONata functions into the target field.

        3. Select Email.
      • Subject: Add an appropriate subject for the new lead to see. For example:
        1. Type Welcome name, and then pause briefly for App Connect to offer you choices based on “name”.
        2. Select a Salesforce / Lead name field, such as Full name.

        (Optional) You can type more text and select more fields to map from Salesforce into the Subject.

      • Body: Complete an appropriate body to send in the email.

        Type text and select fields to map from Salesforce. Alternatively, you can copy and paste the following body example of text, Salesforce fields, and some functions that act on some fields. This example shows the JSONata syntax used to represent fields and functions, which you can adapt as JSONata.

        Hello {{$Trigger.Name}}
        Welcome to Wonders of App Connect. This will help {{$Trigger.Company}} to quickly connect apps to automate tasks and boost productivity

        When pasted into App Connect, the JSONata is given a graphical representation.

        Gmail / Send email ready with fields populated (Click image to view full size)

You have examined the flow created from the template, connected App Connect to the applications used, and made some changes to complete and adapt the flow. Now let’s start the flow and examine it further.

Step 4: Test the event-driven flow

Duration: A few minutes

Although we can start the flow from the flow editor, let’s return to the App Connect dashboard where we can explore more options for running and managing the flow.

Click the Dashboard link in the top left of the flow editor. This displays the App Connect dashboard, with a tile for the flow that we have just completed:

App Connect dashboard showing the tile for the new flow (Click image to view full size)

Test the flow…

  1. Explore the flow tile

    The flow tile on the App Connect dashboard is the quickest way to find information about a running integration.
    When the flow runs, the tile shows an icon with status information such as whether or not the flow ran successfully, any error messages, and the number of records processed; for example:

    • If the flow tile has a green tick, the flow has run successfully; click the tick to see when the flow was last triggered.

      Successful flow icon on a dashboard tile (Click image to view full size)

    • If the tile has a red exclamation point, there’s a problem; click the exclamation point to find out what’s gone wrong.

      Flow error icon on dashboard tile (Click image to view full size)

    You can use the flow tile’s options menu (⋮) to select actions to start, stop, and otherwise manage the flow.

  2. Start the flow

    Open the options menu (⋮) and then click Start flow. The flow tile changes to show a green tick, and the flow is waiting for a new Salesforce lead to be created.

  3. Log in to the Gmail account that you want to use for the new Salesforce lead (that is to receive the email sent by App Connect).
  4. Create a new Salesforce lead:
    1. Log in to Salesforce using the account that you configured in App Connect.
    2. Create a new lead, specifying values for First Name, Last Name, Email (the Gmail account from the previous step), and Company; for example:

      Salesforce window showing new lead being created (Click image to view full size)

      Click Save.

  5. After a brief moment, check the inbox of the Gmail account. You can see an email sent by App Connect (using the Gmail account that you specified on the Gmail / Create email node), containing the data that you specified in the flow; for example:

    New Gmail email sent by App Connect (Click image to view full size)

  6. Return to the App Connect dashboard, and examine the flow’s tile. Hover the mouse cursor over the green tick to see the message about when the flow last ran successfully; for example:

    Flow tile showing last successful run (Click image to view full size)

  7. Next test the Else condition of the flow, which responds to the creation of Salesforce leads without an email address:

  8. Create a new Salesforce lead, but do not specify an Email address; for example:

    Salesforce, creating a new lead without Email address (Click image to view full size)

  9. After a brief moment, check the inbox of the Gmail account. You do not see an email sent by App Connect for the new Salesforce lead, because the email address was not specified.
  10. Return to the App Connect dashboard, and examine the flow’s tile. Hover the mouse cursor over the green tick to see the message that the flow ran successfully. (The flow completed successfully, but output a log message for the Else condition.)
  11. Check the App Connect log for the message added for the Else condition.
    1. From the App Connect hamburger menu, expand Manage then click Logs.

      App Connect menu, Manage / Logs (Click image to view full size)

      This opens the IBM Cloud Logging window for your App Connect.

    2. Examine the log, noting the message added for the Else condition; for example:

      IBM Cloud Logging, showing message added by event-driven flow (Click image to view full size)

    3. To see more detail, expand the message; for example:

      IBM Cloud Logging, showing an expanded message for more detail (Click image to view full size)

You have successfully configured, deployed, and tested your first event-driven flow in App Connect on IBM Cloud.

Join The Discussion

Your email address will not be published. Required fields are marked *