Red Hat Training

A Red Hat training course is available for Red Hat Fuse

Chapter 4. Implement a 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.

To implement, deploy, and test this sample integration, the main steps are:

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.

Before you implement this sample integration, see Section 4.1, “Prerequisites for implementing Salesforce to database integration”.

4.1. Prerequisites for implementing Salesforce to database integration

To implement a Salesforce to database sample integration, 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.

Also, you must be logged in to your Fuse Online environment. If you are not already logged in, see Chapter 2, What to expect when using Fuse Online for the first time.

4.2. Register Fuse Online as a Salesforce client application

You must 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.

If you already registered Fuse Online as a Salesforce client and created a Salesforce connection, skip to Section 4.4, “Create and deploy Salesforce to database sample integration”.

In each Fuse Online environment, there can be only one registration of Fuse Online as a Salesforce client. However, while each Salesforce connection uses the same registration, it can use different user credentials.

To complete this procedure, you must be logged in to your Fuse Online environment. If you are not already logged in, see Chapter 2, What to expect when using Fuse Online for the first time.

Perform these steps to register Fuse Online as a Salesforce client application:

  1. In Fuse Online:

    1. In the left panel, click Settings.
    2. On the Settings page, near the top, to the right of the callback URL, click Copy Callback URL to copy the callback URL for your Fuse Online environment to the clipboard. You will need this URL toward the end of this procedure.
    3. To the right of the Salesforce entry, click Register to display the Client ID and Client Secret fields.
  2. 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.

    1. In Salesforce, in the upper right, click Setup.
    2. In the left panel, select Build > Create > Apps.
    3. Scroll down to Connected Apps and click New.
    4. Enter the required information and then select Enable OAuth Settings.
    5. In the Callback URL field, paste your Fuse Online URL, which you copied at the beginning of this procedure. For example: https://app-proj9128.7b63.fuse-ignite.openshiftapps.com/api/v1/credentials/callback.
    6. 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)
    7. Select Configure ID token and then Include Standard Claims.
    8. Scroll down and click Save.
    9. Scroll up to see that Salesforce indicates a short wait: SF message to wait a few minutes
    10. Click Continue.
    11. Copy the consumer key that Salesforce provides.
  3. Return to your Fuse Online Settings page and paste the Salesforce-provided consumer key into the Fuse Online Salesforce Client ID field.
  4. Return to Salesforce and copy the consumer secret that Salesforce provides.
  5. Return to your Fuse Online Settings page and paste the Salesforce-provided consumer secret into the Fuse Online Salesforce Client Secret field.
  6. Click Save and then click Ok.

4.3. Create a Salesforce connection

A connection to Salesforce requires registration of Fuse Online as an application that can access Salesforce.

If you did not already register Fuse Online, see Section 4.2, “Register 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. After you create a Salesforce connection, you can use it in multiple integrations.

To create a Salesforce connection:

  1. In Fuse Online, in the left panel, click Connections to display available connections.
  2. In the upper right, click Create Connection to display the available connectors. A connector is a template for creating one or more connections.
  3. Click the Salesforce connector.
  4. Click Connect Salesforce to display a Salesforce authorization page. You might need to log in to Salesforce before you see the authorization page.

    Note

    The 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 Section 4.2, “Register Fuse Online as a Salesforce client application”.

  5. Click Allow to return to Fuse Online.
  6. 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.
  7. 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.
  8. 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.4. Create and deploy Salesforce to database sample integration

To create and deploy an integration that uses the Salesforce connection and the database connection, the main steps are:

4.4.1. Choose the start connection

To choose the start connection:

  1. In Fuse Online, on the left, click Integrations.
  2. Click Create Integration.
  3. On the Choose a Start Connection page, click your Salesforce connection. If you specified the example name, you would click SF Connect 1.
  4. On the Choose an Action page, click On create.
  5. In the Object name field, select Lead.
  6. Click Done to add the start connection to the integration.

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.4.2. Choose the finish connection

To add the finish connection to the integration:

  1. 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.
  2. On the Choose an Action page, click Invoke SQL stored procedure, which passes data to a stored procedure.
  3. In the Procedure Name field, click and select 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.
  4. Click Done to add the finish connection to the integration.

4.4.3. Add a data mapping step

To add a step that maps Salesforce fields to database fields:

  1. In Fuse Online, in the left panel, hover over the plus sign immediately after the start connection to display a pop-up in which you click Add a Step.
  2. 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.
  3. Map the Salesforce Company field to the database company field:

    1. On the left, in the Sources panel, click Company.
    2. On the right, in the Target panel, click company. The data mapper displays a line from the source field to the target field.
  4. Map the Sources (Salesforce) Email field to the Target (database) email field.
  5. Map two Salesforce fields (FirstName and LastName) to the database first_and_last_name field:

    1. In the Target panel, click first_and_last_name.
    2. In the Sources panel, click FirstName.
    3. 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.

  6. Add the following mappings:

    Map This Salesforce FieldTo This Database Field

    LeadSource

    lead_source

    Status

    lead_status

    Phone

    phone

    Rating

    rating

  7. In the upper right, click Done.

4.4.4. Give the integration a name and deploy it

The sample integration is complete. To deploy it:

  1. In Fuse Online, in the upper right, click Publish to give it a name.
  2. In the Integration Name field, enter a name for the integration. For example, Salesforce to Database Sample Integration.
  3. In the upper right corner, click Publish.

Fuse Online displays the integration summary page with 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.

Note

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:

  1. In the left panel, click Integrations.
  2. In the entry for the integration that you want to stop, click ThreeVerticalDotsKebab on the far right.
  3. In the popup, click Stop.

After stopping an integration, start another integration as follows:

  1. In the left panel, click Integrations.
  2. In the entry for the integration that you want to start, click ThreeVerticalDotsKebab on the far right.
  3. In the popup, click Publish.

4.5. Confirm that the Salesforce to database integration works

To confirm that the Salesforce to database integration is working:

  1. In the left panel, click Integrations.
  2. 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.
  3. 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.
  4. In a new browser window, insert todo- in front of the URL for your Fuse Online installation. For example: https://todo-app-proj7614.6a63.fuse-ignite.openshiftapps.com/.

    Your Fuse Online installation 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) file for the To Do app to create an API client connector.

  5. In the To Do App display, you should see a notification that a new lead was created in the database.

4.6. Clean up your integration

When you are done working with a sample integration, stop it and delete it:

  1. In Fuse Online, in the left panel, click Integrations.
  2. In the main panel, identify the entry for the sample integration that you want to stop.
  3. In that entry, to the right, click Kebab Menu and then click Stop.
  4. Click Stop to confirm that you want to stop running the integration.
  5. In the entry for the integration that you just stopped, to the right, click Kebab Menu and then click Delete.
  6. Click Delete to confirm that you want to delete the integration.