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:

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

4.2. Register Ignite as a Salesforce client

You must register your installation of Ignite as an 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 installation of Ignite with Salesforce only once.

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

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

Perform these steps to register Ignite as a Salesforce client:

  1. In Ignite:

    1. In the left panel, click Settings.
    2. Near the top of the OAuth Application Management page, where you see During registration, enter this callback URL:, copy that URL to the clipboard.
    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 Ignite 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
      • Allow access to your unique identifier
      • Perform requests on your behalf at any time
    7. Select Include 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 Ignite installation Settings page and paste the Salesforce-provided consumer key into the Salesforce Client ID field.
  4. Back in Salesforce, copy the consumer secret that Salesforce provides.
  5. Return to your Ignite installation Settings page and paste the Salesforce-provided consumer secret into the Salesforce Client Secret field.
  6. Click Save and then click Ok.

4.3. Create a Salesforce connection

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

If you did not already register Ignite, see Section 4.2, “Register Ignite as a Salesforce client”.

Be sure to wait 2 - 10 minutes after registering your Ignite 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 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 Ignite 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 Ignite callback URL is specified according to the instructions in Section 4.2, “Register Ignite as a Salesforce client”.

  5. Click Allow to return to Ignite.
  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 is now available.

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. 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. 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 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 Sources panel, click FirstName.
    2. In the Target panel, click first_and_last_name.
    3. In the Mapping Details panel, under Action, select Combine.
    4. Just above that, click Add Source.
    5. Under Source, in the input field, start to type LastName. When /LastName appears below the field, click it. The data mapper displays a line from the Sources LastName field to the Target first_and_last_name 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 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.

Ignite displays the integration summary page with a Publishing spinning circle. Ignite 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 unpublish an integration before you can publish (start running) another one.

If you are using a Fuse Online evaluation account, then only one integration at a time can be running (published). If you already created one of the other sample integrations and that integration is running then this integration is automatically in the Unpublished state. You must stop the running integration by unpublishing it. You can then publish this integration.

If you are already running the maximum number of integrations, follow these steps to unpublish (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 Unpublish.

After unpublishing 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 Published integration, which means that it is running. If you used the example name, you would see that Salesforce to Database Sample Integration is Published.
  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 Ignite installation. For example: https://todo-app-proj7614.6a63.fuse-ignite.openshiftapps.com/.
  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, unpublish it and delete it:

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