Retrieving the history of a new Salesforce lead from IBM Db2 to email the lead owner
Learn how to use IBM® App Connect on IBM Cloud® to create an event-driven flow such that when a new lead is created in Salesforce, if App Connect finds that lead in the IBM Db2® database then it sends an email to the Salesforce lead owner giving them the Db2 history of the lead.
Scenario
You are a Sales line-of-business person who has been using Db2 to store details of all your prospects or leads with other customer data. You have decided to switch over to Salesforce as your Customer Relationship Management (CRM) system, and started using it to record all new leads.
When a new lead is created in Salesforce, you want the lead owner to be automatically notified if the lead exists in Db2. For this, you use App Connect to easily create an event-driven flow that is triggered when a new lead is created in Salesforce, and checks if the lead is an existing lead in the Db2 leads table, and if the lead does exist so sends an email to lead owner giving them the Db2 history of the lead.

(Click image to view full size.)
First, find or create everything you need:
This document assumes that you have signed up for free or trial accounts with Salesforce and IBM Db2 database server, or that you have business accounts.
- An App Connect subscription.
- Obtain account details for connecting App Connect to your applications (if you haven't already
connected App Connect to these applications):
- For Salesforce, you need user ID and password credentials to connect. If you want to create a free Salesforce account to test out App Connect, make sure that you create a Developer account rather than a Trial account. For more information, see How to use IBM App Connect with Salesforce.
- To connect to IBM Db2, you need the Db2 database server host name, port, user ID, password, database name, schema name, and database manager authentication type. If you are not the owner or administrator of your Db2 instance, you can obtain this information from your Db2 administrator. You'll also need to specify the name of the network (configured using the IBM Secure Gateway Client) for connecting to a Db2 server in a private network. If you've previously used the Secure Gateway Client to set up a network connection for an App Connect application that is on the same private network as the Db2 server, you can use this network connection with Db2. For more information about completing these connection fields, see How to use IBM App Connect with IBM Db2. Important: Ensure that the Secure Gateway Client has been started. If you need to, you
can start the Secure Gateway Client as described in Configuring a private network for App Connect Designer: Finally, start
and configure the Secure Gateway Client.
You can connect to the IBM Db2 app either from the Applications tab on the Catalog page, or when you add the app to a flow. After you connect, the Db2 database objects, and applicable events and actions can be discovered.
Tip:- Immediately after you connect, rename your account with a meaningful name that helps you identify which schema the account relates to. You'll find this useful if you'd like to access multiple schemas in your flows. You can rename an account only from the Applications tab on the Catalog page, and before it's used in a flow.
- If you'd like to access multiple schemas in your flows, you'll need to add an account for each
schema whose objects you want to run operations on.
For information about renaming accounts and setting up multiple accounts, see Connecting to applications and APIs
- The OAuth client ID, client secret, access token, and refresh token for your Gmail account. For more information about how to get the required values, see How to use IBM App Connect with Gmail.
Next, create your flow:
Using the IBM App Connect Designer authoring experience, you can create your flow from scratch.
Complete the following steps in App Connect Designer:
- From the Dashboard, click (or in earlier versions).
Complete the following steps. As you progress, App Connect automatically saves your changes. If you navigate away from the flow at any stage, the flow is saved as a draft flow that you can complete at another time.
- Enter a name that identifies the purpose of your flow; for example: Retrieve lead history from Db2 for each Salesforce lead
- Select as the event that is to trigger the flow.
- Click the (+) and then scroll down to IBM Db2.
- Select
Figure 2. IBM Db2 / Retrieve LEADS record action (Click image to view full size.)
as the action. - Map the Retrieve LEADS where clause fields with the response from Salesforce lead
object.
Figure 3. IBM Db2 / Retrieve LEADS records Where Clause Mappings (Click image to view full size.)
- Select the If(Conditional) node from Toolbox and use the count function to check the leads count on the response from Db2 Retrieve node
Figure 4. IF Condition node with count function to check the leads count on response from Db2 Retrieve node (Click image to view full size.)
- Inside the IF flow node select
Figure 5. Salesforce / Retrieve user node to get lead owner's email address using lead owner's id (Click image to view full size.)
to get the Lead Owner's email address and map the User ID with Owner
ID from salesforce New Lead response - Use
Figure 6. Gmail / Send email node to send an email to lead owner's id with the history of the lead (Click image to view full size.)
to send an email to the lead owner along with the lead's history - From the banner, open the options menu [⋮] then click Start flow. Then
click Dashboard to exit the flow. Your flow is displayed on your Dashboard
and is listening for your event ; the addition of a new contact in Salesforce.
Figure 7. The flow tile on the Dashboard, showing that the flow is running and listening for events (Click image to view full size.)
Finally, test your flow:
- Log in to Salesforce using the account that you configured in App Connect.
- Create a new Salesforce lead that already exists in your Db2 database, and then save the
lead.
Figure 8. (Click image to view full size.)
- After a short while, check your email inbox for a new email containing the history of the lead obtained from the Db2 database.
Figure 9. History of the existing lead is fetched from Db2 (Click image to view full size.)
- Examine the App Connect Dashboard. If the flow ran successfully, the flow tile shows a green
tick:
Figure 10. Flow tile showing the last successful run of the flow (Click image to view full size.)
Conclusion
Congratulations, you have created a flow that is triggered when a new lead is added to Salesforce, and retrieves the history of that lead from a leads table in IBM Db2, and then sends an email to the Lead owner with lead's history.