Chapter 4. Implementing the Salesforce to database sample integration
This sample integration captures updates in Salesforce and then calls a database stored procedure, which synchronizes that database with the Salesforce updates.
Prerequisites
You need an account in a Salesforce installation that is used for development. This account must have Salesforce API access, which is available in a Salesforce Enterprise account or a Salesforce Developer account. To obtain a free developer account, visit https://developer.salesforce.com/signup. It takes less than two minutes to obtain a Salesforce account.
If you already created the Twitter to Salesforce sample integration:
- Fuse Online is already registered as a Salesforce client. You do not need to do this again.
- You already have a Salesforce connection, which you can reuse in this sample integration.
If you did not already create the Twitter to Salesforce sample integration, then you must register Fuse Online as a Salesforce client and create a Salesforce connection in order to complete the Salesforce to database sample integration.
- You must be logged in to your Fuse Online environment. If you are not already logged in, see What to expect the first time that you use Fuse Online.
To implement, deploy, and test this sample integration, the main steps are:
- Section 4.1, “Registering Fuse Online as a Salesforce client application”
- Section 4.2, “Creating a Salesforce connection”
- Section 4.3, “Creating and deploying the Salesforce to database sample integration”
- Section 4.4, “Confirming that the Salesforce to database integration works”
- Section 4.5, “Cleaning up your integration”
4.1. Registering Fuse Online as a Salesforce client application
In an integration, to connect to Salesforce, the first thing you must do is register your Fuse Online environment as a client application that can access Salesforce. This lets you create any number of integrations that connect to Salesforce. In other words, you need to register a particular Fuse Online environment with Salesforce only once.
In each Fuse Online environment, there can be only one registration of Fuse Online as a Salesforce client application. However, while each Salesforce connection uses the same registration, it can use different user credentials.
If you already registered Fuse Online as a Salesforce client and created a Salesforce connection, skip to Creating Salesforce to database integration.
Prerequisite
You are logged in to Fuse Online. The URL for accessing Fuse Online is in the email message that welcomed you to the Red Hat Fuse Online Evaluation program.
Procedure
In Fuse Online:
- In the left panel, click Settings.
- On the Settings page, near the top, to the right of the callback URL, click to copy the callback URL for your Fuse Online environment to the clipboard. You will need this URL toward the end of this procedure.
- To the right of the Salesforce entry, click Register to display the Client ID and Client Secret fields.
In another browser tab, log in to your Salesforce account and follow the steps below to create a connected app. These instructions assume that you are using the Salesforce Classic user interface. To switch from the Salesforce Lightning Experience interface, click your profile icon and select Switch to Salesforce Classic. For additional information, see the Salesforce documentation for Create a Connected App.
- In Salesforce, in the upper right, click Setup.
- In the left panel, select Build > Create > Apps.
- Scroll down to Connected Apps and click New.
- Enter the required information and then select Enable OAuth Settings.
-
In the Callback URL field, paste your Fuse Online URL, which you copied at the beginning of this procedure. For example:
https://app-proj912876.7b63.fuse-ignite.openshiftapps.com/api/v1/credentials/callback
. For OAuth Scopes, add:
- Access and manage your data (api)
- Allow access to your unique identifier (openid)
- Perform requests on your behalf at any time (refresh_token, offline_accesss)
- Select Configure ID token and then Include Standard Claims.
- Scroll down and click Save.
- Scroll up to see that Salesforce indicates a short wait:
- Click Continue.
- Copy the consumer key that Salesforce provides.
- Return to your Fuse Online Settings page and paste the Salesforce-provided consumer key into the Fuse Online Salesforce Client ID field.
- Return to Salesforce and copy the consumer secret that Salesforce provides.
- Return to your Fuse Online Settings page and paste the Salesforce-provided consumer secret into the Fuse Online Salesforce Client Secret field.
- Click Save and then click Ok.
4.2. Creating a Salesforce connection
To create an integration that accesses data in Salesforce, you must first create a Salesforce connection. After you create a Salesforce connection, you can use it in multiple integrations.
Prerequisites
- You are logged in to Fuse Online. The URL for accessing Fuse Online is in the email message that welcomed you to the Red Hat Fuse Online Evaluation program.
- Fuse Online is open in a web browser.
- You must have already registered your Fuse Online environment as an application that can access Salesforce.
You added the Salesforce client ID and client secret that you received after registration to the Fuse Online Settings page.
If you did not already register Fuse Online, see Registering Fuse Online as a Salesforce client application.
Be sure to wait 2 - 10 minutes after registering your Fuse Online installation as a Salesforce client before you try to create a Salesforce connection.
Procedure
- In Fuse Online, in the left panel, click Connections to display available connections.
- In the upper right, click Create Connection to display the available connectors. A connector is a template for creating one or more connections.
- Click the Salesforce connector.
Click Connect Salesforce to display a Salesforce authorization page. You might need to log in to Salesforce before you see the authorization page.
If Connect Salesforce does not appear, then your Fuse Online environment is not registered as a Salesforce client application. See Registering Fuse Online as a Salesforce client application. When you try to create a Salesforce connection and your Fuse Online environment is not registered as a Salesforce client application, then Fuse Online displays multiple fields that prompt for authorization information. While you can create a Salesforce connection by entering values in these fields, it is not recommended.
NoteThe following error indicates that Salesforce does not have the correct Fuse Online callback URL:
error=redirect_uri_mismatch&error_description=redirect_uri%20must%20match%20configuration
If you get this error message, then in Salesforce, ensure that the Fuse Online callback URL is specified according to the instructions in Registering Fuse Online as a Salesforce client application.
- Click Allow to return to Fuse Online.
-
In the Connection Name field, enter your choice of a name that helps you distinguish this connection from any other connections. For example, enter
SF Connect 1
. -
In the Description field, optionally enter any information that is helpful to know about this connection. For example, enter
Sample Salesforce connection that uses my Salesforce login credentials.
- In the upper right, click Create to see that the connection you created is now available. If you entered the example name, you would see that SF Connect 1 appears as a connection that you can choose to add to an integration.
4.3. Creating and deploying the Salesforce to database sample integration
To create and deploy an integration that uses the Salesforce connection that you created and the database connection that is provided with Fuse Online, the main steps are:
Prerequisites
- You registered your Fuse Online environment as a Salesforce client.
- You created a Fuse Online Salesforce connection.
- Fuse Online is open and you are logged in.
4.3.1. Choosing the start connection
In Fuse Online, to create the sample Salesforce to database integration, the first task is to choose the start connection.
Prerequisites
- You created a Salesforce connection.
Procedure
- In Fuse Online, on the left, click Integrations.
- Click Create Integration.
- On the Choose a Start Connection page, click your Salesforce connection. If you specified the example name, you would click SF Connect 1.
- On the Choose an Action page, click On create.
- In the Object name field, select Lead.
- Click Next to add the start connection to the integration.
Next step
When the integration is running, after connecting to Salesforce, the integration watches for notifications that a Salesforce Lead record was created. When the integration finds such a notification, it passes the new lead’s data to the next step in the integration. However, before you can add the next step, you must choose the integration’s finish connection.
4.3.2. Choosing the finish connection
In Fuse Online, to continue creating the Salesforce to database sample integration, after you add the start connection, you add the finish connection to the integration.
Prerequisites
- You added the Salesforce connection to the integration as the start connection.
- Fuse Online is prompting you to add the finish connection.
Procedure
- In Fuse Online, on the Choose a Finish Connection page, click the PostgresDB connection. This integration finishes by using the credentials defined in this database connection to connect to the provided sample database.
- On the Choose an Action page, click Invoke stored procedure, which passes data to a stored procedure.
- In the Procedure Name field, accept add_lead, which is the provided stored procedure to run in the sample database. The selected procedure determines the requirements for additional steps in the integration, for example, which Salesforce data fields need to be mapped to which database fields.
- Click Next to add the finish connection to the integration.
4.3.3. Adding a data mapping step
To continue creating the Salesforce to database sample integration, add a data mapping step that correlates Salesforce lead fields to fields in the sample database.
Prerequisites
- The integration’s start connection is to Salesforce.
- The integration’s finish connection is to the PostgresDB sample database.
Procedure
- In Fuse Online, in the visualization panel on the left, click the plus sign.
- On the Choose a Step page, click Data Mapper and wait a few moments. When the data fields appear, the Sources panel on the left displays the Salesforce fields and the Target panel on the right displays the database fields.
Map the Salesforce
Company
field to the databasecompany
field:- On the left, in the Sources panel, click Company.
- On the right, in the Target panel, click company. The data mapper displays a line from the source field to the target field.
-
Map the Sources (Salesforce)
Email
field to the Target (database)email
field. Map two Salesforce fields (
FirstName
andLastName
) to the databasefirst_and_last_name
field:- In the Target panel, click first_and_last_name.
- In the Sources panel, click FirstName.
In the Sources panel, hover over LastName and press CTRL-Mouse1 (CMD-Mouse1 on MacOS).
The data mapper automatically changes the field action from Map to Combine.
When you are done you should see a line from each of the source fields to the target field.
Add the following mappings:
Map This Salesforce Field To This Database Field LeadSource
lead_source
Status
lead_status
Phone
phone
Rating
rating
- In the upper right, click Done.
4.3.4. Giving the integration a name and deploying it
When the Salesforce to database sample integration is complete then you can deploy it and see how it works.
Prerequisites
- The integration’s start connection is Salesforce.
- The integration’s finish connection is to the sample database that is provided with Fuse Online.
- You just added a data mapping step to the integration.
Procedure
- In Fuse Online, in the upper right, click Publish to give it a name.
-
In the Integration Name field, enter a name for the integration. For example,
Salesforce to Database Sample Integration
. In the upper right corner, click Publish.
Fuse Online starts to deploy the integration and then displays the list of integrations in this environment. The entry for your Salesforce to database integration displays a progress indicator that shows the publishing stages. Fuse Online is generating the runtime for the integration and will start it when the runtime is ready. This takes a few minutes.
A Fuse Online account is limited to a specific number of integrations that can be running at one time. For details, see the pricing plan. If you are already running the maximum number of integrations, then you must stop an integration before you can start running another one.
If you are using a Fuse Online evaluation account, then only one integration at a time can be running. If you already created one of the other sample integrations and that integration is running then this integration is automatically in the Stopped state. You must stop the running integration and then you can then publish this integration.
If you are already running the maximum number of integrations, follow these steps to stop an integration:
- In the left panel, click Integrations.
- In the entry for the integration that you want to stop, click on the far right.
- In the popup, click Stop.
After stopping an integration, start another integration as follows:
- In the left panel, click Integrations.
- In the entry for the integration that you want to start, click on the far right.
- In the popup, click Publish.
4.4. Confirming that the Salesforce to database integration works
To confirm that the Salesforce to database integration is working, create a new lead in Salesforce and then open the web app that Fuse Online provides for viewing updates to the sample database.
Prerequisites
- In Fuse Online, Running appears next to the name that you specified for the Salesforce to database sample integration when you published it.
- You can access your Salesforce account.
Procedure
- In the left panel, click Integrations.
- If necessary, wait until your sample integration is a Running integration. If you used the example name, you would see that Salesforce to Database Sample Integration is Running.
- In your Salesforce installation, create a new lead. Be sure to enter data in the fields that you mapped: Company, Email, FirstName, LastName, LeadSource, Status, Phone, and Rating.
In a new browser window, insert
todo-
in front of the URL for your Fuse Online environment. For example:https://todo-app-proj761432.6a63.fuse-ignite.openshiftapps.com/
.Your Fuse Online environment provides the To Do app, which has a REST API for accessing a database that contains tasks. In the AMQ to REST API sample integration tutorial, there are instructions for uploading an OpenAPI (Swagger) document for the To Do app to create an API client connector.
- In the To Do App display, you should see a notification that a new lead was created in the database.
Optionally, view the integration log to troubleshoot an unexpected result or to learn more about integration execution:
- In Fuse Online, in the left panel, click Integrations.
- Click the entry for your Salesforce to database integration.
- In the integration’s summary page, click the Activity tab.
- Click the integration execution for which you want to view activity information.
4.5. Cleaning up your integration
When you are done working with a sample integration, you should stop it and delete it so that you can use the resources for another integration.
Prerequisites
- You are finished working with a sample integration that you published.
Procedure
- In Fuse Online, in the left panel, click Integrations.
- In the main panel, identify the entry for the sample integration that you want to stop.
- In that entry, to the right, click and then click Stop.
- Click Stop to confirm that you want to stop running the integration.
- In the entry for the integration that you just stopped, to the right, click and then click Delete.
- Click Delete to confirm that you want to delete the integration.