Red Hat Training

A Red Hat training course is available for Red Hat Fuse

Chapter 3. Implement a Twitter to Salesforce sample integration

This sample integration watches Twitter for tweets that mention a particular Twitter user. When the integration finds such tweets, it filters them so that only those tweets that contain the text you specify cause the integration to continue.

For tweets that contain the specified text, the integration passes data related to the tweet, including the Twitter user name, to Salesforce and Salesforce creates a new contact.

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

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

3.1. Prerequisites for implementing Twitter to Salesforce integration

To implement a Twitter to Salesforce sample integration:

  • You need a Twitter account. You can obtain one at http://twitter.com.
  • 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.

3.2. Register Ignite as a Twitter client

You must register your installation of Ignite as an application that can access Twitter. This lets you create any number of integrations that connect to Twitter. In other words, you need to register a particular installation of Ignite with Twitter only once.

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

Perform these steps:

  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 the URL at the end of the sentence to the clipboard.
    3. To the right of the Twitter entry, click Register to display the Client ID and Client Secret fields.
  2. In another browser tab, go to the Twitter Application Management web site at https://apps.twitter.com and do the following:

    1. Confirm that the URL is apps.twitter.com and not just twitter.com.
    2. If you are not already logged in to the Twitter Application Management site, log in.
    3. Click Create New App.
    4. In the Name field, enter a name for your new app. This name must be unique among all names of apps registered with Twitter.
    5. In the Description field, enter helpful information. Twitter requires some input in this field.
    6. In the Website field, paste the URL that you copied at the beginning of this procedure and remove api/v1/credentials/callback from the end of the URL.
    7. In the Callback URL field, paste the URL again. It should be something like this: https://app-proj9128.7b63.fuse-ignite.openshiftapps.com/api/v1/credentials/callback.
    8. Click Yes to agree to the Twitter developer agreement.
    9. Click Create your Twitter application.
    10. Click the Keys and Access Tokens tab.
    11. Copy the Consumer Key.
  3. On your Ignite installation Settings page, paste the Twitter consumer key into the Twitter Client ID field.
  4. On the Twitter Keys and Access Tokens tab, copy the Consumer Secret and paste it into the Ignite Twitter Client Secret field.
  5. Click Save and then click Ok.

3.3. Create a Twitter connection

A connection to Twitter requires registration of Ignite as an application that can access Twitter. If you did not already register Ignite, see Section 3.2, “Register Ignite as a Twitter client”.

After you create a Twitter connection, you can use it in multiple integrations.

To create a Twitter connection:

  1. In Ignite, in the left panel, click Connections to display any available connections.
  2. In the upper right, click Create Connection to display the available connectors. A connector is a template that you use to create one or more connections.
  3. Click the Twitter connector.
  4. Click Connect Twitter to display a Twitter authorization page. You might need to log in to Twitter before you see the authorization page.
  5. Click Authorize app 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 Twitter Connect 1.
  7. In the Description field, optionally enter any information that is helpful to know about this connection. For example, enter Sample Twitter connection that uses my Twitter 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 Twitter Connect 1 is now available.

3.4. 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 3.6, “Create and deploy Twitter to Salesforce 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.

3.5. 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 3.4, “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 3.4, “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.

3.6. Create and deploy Twitter to Salesforce sample integration

To create and deploy an integration that uses the Twitter and Salesforce connections you created, the main steps are:

3.6.1. Choose the start connection

To choose the start connection:

  1. On the left, click Integrations.
  2. In the upper right, click Create Integration.
  3. On the Choose a Start Connection page, click the Twitter connection you created. If you gave it the example name, you would click Twitter Connect 1. When the integration starts, it uses the credentials defined in this connection to connect to Twitter.
  4. On the Choose an Action page, click Mention.

After connecting to Twitter, the integration monitors Twitter for mentions that include your Twitter screen name. A match triggers the next step in the integration. However, before you add steps that operate on data between connections, you choose the connection that the integration uses to finish its work.

3.6.2. Choose the finish connection

To add the finish connection to the integration:

  1. On the Choose a Finish Connection page, click the Salesforce connection you created. If you gave it the example name, you would click SF Connect 1. This integration finishes by using the credentials defined in this connection to connect to Salesforce.
  2. On the Choose an Action page, click New record.
  3. On the next page, accept Contact as the Salesforce record to create.
  4. Click Done to add the finish connection to the integration.

3.6.3. Add a basic filter step

Add a basic filter step that checks tweets that mention you for particular content. The integration continues only if that content is present.

To add a basic filter step:

  1. In the main panel, click Add a step.
  2. Click Basic Filter.
  3. In the first field (The data you want to evaluate), start to enter text and when text appears below the field, click it. This indicates that the content to filter for is in the Twitter text field, which contains the text of the tweet.
  4. Accept contains as the condition to be met for the integration to continue.
  5. In the last field, enter #RedHatIsGreat or some other text you choose. A tweet that mentions you must contain the text you enter here for the integration to continue operating on this data.
  6. Click Done to complete the basic filter step.

3.6.4. Add a data mapping step

Add a data mapping step that correlates Twitter mention fields to Salesforce contact fields:

  1. In the left panel, hover over the plus sign between the filter step and the finish 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 Twitter fields and the Target panel on the right displays the Salesforce fields.
  3. Map the Twitter name field to the Salesforce FirstName and LastName fields:

    1. In the Sources panel, click the magnifying glass magnifying glass to display the search field and enter name.
    2. Under the user folder, click the name field.
    3. In the Mapping Details panel, under Action, click the down caret and select Separate.
    4. Below that, under Targets, in the input field, start to type FirstName. When /FirstName appears below the field, click it. The data mapper displays a line from the Twitter name field to the Salesforce FirstName field.
    5. In the lower right, click Add Target.
    6. In the new target, in the input field, start to type LastName. When /LastName appears below the field, click it. The data mapper displays another line from the Twitter name field, but this time it goes to the Salesforce LastName field. The blue lines indicate the current focus.
  4. Map the Twitter screenName field to the Salesforce Title field:

    1. In the Sources panel, scroll down to click the screenName field.
    2. On the right, at the top of the Target panel, click the magnifying glass magnifying glass to display the search field and enter Title.
    3. Click the Title field. The data mapper displays a line from the Twitter screenName field to the Salesforce Title field.
  5. Map the Twitter text field to the Salesforce Description field:

    1. In the Sources search field, enter text and under Status, click the text field.
    2. In the Target search field, enter description and then click the Salesforce Description field to create the mapping.
    3. In the upper right, click the grid icon grid to display the list of mappings, which should look like this: Data Mappings
  6. In the upper right, click Done.

3.6.5. Give the integration a name and deploy it

The sample integration is complete. To deploy it:

  1. At the top of the left panel, in the Integration Name field, enter a name of your choice that distinguishes this integration from any other integrations. For example: Twitter to Salesforce Sample Integration.
  2. 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.

3.7. Confirm that the Twitter to Salesforce integration works

To confirm that the Twitter to Salesforce sample integration is working:

  1. In the panel on the left, click Integrations to see that the integration you created is a Published integration, which means that it is running. If you entered the example name, you would see that Twitter to Salesforce Sample Integration is running.
  2. Confirm that the integration does not create a contact record when a tweet does not contain the text you specified in the basic filter step:

    1. In Twitter, send a tweet that:

      • Mentions your Twitter handle
      • Does not contain the text you specified in the basic filter step

        For example: @Aslan #likesRedHat.

    2. Wait for the polling interval to elapse, which can be 30 - 60 seconds.
    3. In Salesforce, confirm that a contact record with your name does not exist.
  3. Confirm that the integration creates a new contact record when it should:

    1. In Twitter, send a tweet that:

      • Mentions your Twitter handle
      • Contains the text you specified in the basic filter step

        For example: @Aslan knows #RedHatIsGreat.

    2. Wait for the polling interval to elapse.
    3. In Salesforce, locate a contact record that has your name, the text of your tweet in the Description field, and your Twitter screen name in the Title field.

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