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:

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

  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. Click the Salesforce entry 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-proj912876.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.
  7. Click the Salesforce entry to collapse it.

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

  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.

    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.

    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 Registering Fuse Online as a Salesforce client application.

  5. Click Allow to return to Fuse Online.
  6. In the 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. Click Save 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

  1. In Fuse Online, on the left, click Integrations.
  2. Click Create Integration.
  3. On the Choose a 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, to the right of On create, click Select.
  5. In the Object name field, select Lead.
  6. 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

  1. In Fuse Online, on the Choose a 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, select Invoke stored procedure, which passes data to a stored procedure.
  3. 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.
  4. 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

  1. In Fuse Online, in the integration visualization, click the plus sign.
  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).

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

  1. In Fuse Online, in the upper right, click Publish to give it a name.
  2. In the Name field, enter a name for the integration. For example, Salesforce to Database Sample Integration.
  3. Click Save and 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.

  4. 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.
  5. 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.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

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

  5. In the To Do App display, you should see a notification that a new lead was created in the database.
  6. Optionally, view the integration log to troubleshoot an unexpected result or to learn more about integration execution:

    1. In Fuse Online, in the left panel, click Integrations.
    2. View your Salesforce to database integration.
    3. In the integration’s summary page, click the Activity tab.
    4. 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

  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.