Invoke an integration for a Salesforce Change Data Capture (CDC) event (original) (raw)

Learn how to create a sample integration in Application Integration using the Salesforce trigger. The following steps describe how to configure the trigger, tasks, connectors, and data mappings required to run a complete integration.

In this quickstart, you will use the Salesforce trigger to invoke an integration in Application Integration for a Salesforce Change Data Capture (CDC) event as shown in the following figure:

Sample sequence diagram Sample sequence diagram

A Salesforce trigger is subscribed to the Salesforce opportunity channel. Data changes to the Salesforce opportunity invokes an Application Integration which extracts the status of the Salesforce opportunity. If the status is closed, the integration extracts the opportunity details and writes the data to a Cloud SQL instance using a connector. If there is a data change, but the status remains open, the integration sends a message to a pub/sub topic using a connector.

The following steps describe how to configure the trigger, tasks, authentication profiles, edges, variables, and data mapping required to run a successful integration.

Before you begin

Create a new integration

To create a new integration, perform the following steps:

  1. In the Google Cloud console, go to the Application Integration page.
    Go to Application Integration
  2. Click Integrations from the left navigation menu to open the Integrations page.
  3. Click Create integration.
  4. Enter a name and description in the Create Integration dialog. For example, Demo-CDC-Opportunities.
  5. Select a region for the integration.
  6. Click Create to open the integration designer.

Add and configure the Salesforce trigger

To add and configure a Salesforce trigger to the integration, perform the following steps:

  1. In the integration designer, select Add a task/trigger > Triggers to display a list of available triggers.
  2. Click and place the Salesforce trigger element in the integration designer.
  3. Click the Salesforce trigger element on the canvas to open the configuration pane of the trigger.
  4. Configure the following fields under Trigger Input:
    • Event type: Select Change Data Capture (CDC) from the drop-down list.
    • Salesforce instance configuration: Click the + Add new Salesforce instance configuration option from the drop-down list.
      The Add Salesforce instance configuration dialog appears.
      * Salesforce instance connection name: Enter a connection name for the Salesforce instance. For example, CDC-PlatformUser.
      * Salesforce domain: Enter your Salesforce domain name. You can find this information from your Salesforce account > View profile page.
      * Authentication profile: Select an authentication profile. If you don't have an authentication profile, create a new profile. For information, see Create a new authentication profile.
      * Click Add.
    • Salesforce channel configuration: Click the + Add new Salesforce channel configuration option from the drop-down list.
      The Add Salesforce channel dialog appears.
      * Salesforce object name: Enter Opportunity.
      * Click Add.
    • Operation: Select Update from the drop-down list
      Changes to the properties are saved automatically.

Add and configure tasks

This tutorial uses the Connectors and Data Mapping tasks. Configuration details for each of these tasks are described as follows.

Configure a Connectors task with a Cloud SQL for MySQL connection

Perform the following steps to configure a Connectors task to insert records into an existing Cloud SQL table using the Cloud SQL for MySQL connection:

  1. Select +Add a task/trigger > Tasks in the integration designer to display the list of available tasks.
  2. Click and place the Connectors element in the integration designer.
  3. Click the Connectors task element on the designer to view the Connectors task configuration pane.
  4. Click and change the Connectors name as Insert row to Cloud SQL.
  5. Click Configure task.
    The Configure connector task dialog appears.
  6. Do the following in the Configure connector task dialog:
    1. Select the connection region.
    2. Once a region is chosen, the Connection column appears. Select your Cloud SQL for MySQL connection from the list of available connections.
    3. Once a connection is chosen, the Type column appears. Select Entities and then OPPORTUNITIES from the list of available entities.
    4. Once a type is chosen, the Operation column appears. Select Create.
    5. Click Done to complete the connection configuration and close the pane.

Configure a Connectors task with a Cloud Pub/Sub connection

Perform the following steps to configure a Connectors task to publish a Pub/Sub message using the Cloud Pub/Sub connection:

  1. Select +Add a task/trigger > Tasks in the integration designer to display the list of available tasks.
  2. Click and place the Connectors element in the integration designer.
  3. Click the Connectors task element on the designer to view the Connectors task configuration pane.
  4. Click and change the Connectors name as Publish to cloud pub/sub.
  5. Click Configure task.
    The Configure connector task dialog appears.
  6. Do the following in the Configure connector task dialog:
    1. Select the connection region.
    2. Once a region is chosen, the Connection column appears. Select your Pub/Sub connection from the list of available connections.
    3. Once a connection is chosen, the Type column appears. Select Actions and then publishMessage from the list of available actions.
    4. Click Done to complete the connection configuration and close the pane.

Configure the Data Mapping task

Do the following to configure a Data Mapping task.:

  1. Select Add a task/trigger > Tasks to display a list of available tasks.
  2. Click and place the Data Mapping element in the integration designer.
  3. Click the Data Mapping element on the designer to open the configuration pane of the task.
  4. Click Open Data Mapping Editor.
    The Data Mapping Editor lets you to map input variables to the desired output variables, using the available transformation functions. The output is then available as a variable to any other integration task or trigger. For more details on passing data as variables, see Using variables in Application Integration.
  5. Click + Add new variable and create the following output variables:
    Output variable name Data type
    OpportunityIsClosed Boolean
    OpportunityId String
    PubSubMessage String
  6. Create the following mapping between the SalesforceTriggerCdcPayload variable and the Connector input payload variables as shown in the following table:
    Input Output
    SalesforceTriggerCdcPayload.GET_PROPERTY("IsClosed").TO_BOOLEAN() OpportunityIsClosed
    SalesforceTriggerCdcPayload.GET_PROPERTY("Id").TO_STRING() OpportunityId
    OpportunityId.TO_DOUBLE() connectorInputPayload.ID(Insert row to Cloud SQL)
    SalesforceTriggerCdcPayload.GET_PROPERTY("Name").TO_STRING() connectorInputPayload.NAME(Insert row to Cloud SQL)
    SalesforceTriggerCdcSnapshot.GET_PROPERTY("Amount").TO_DOUBLE() connectorInputPayload.AMOUNT(Insert row to Cloud SQL)
    SalesforceTriggerCdcSnapshot.GET_PROPERTY("CloseDate").TO_STRING() connectorInputPayload.DT_CLOSE(Insert row to Cloud SQL)
    OpportunityId.CONCAT(" is still open") PubSubMessage
    PubSubMessage connectorInputPayload.message(Publish to cloud pub/sub)

Once your mapping is complete, close the pane. Any changes will be autosaved.

Add edge connection

An edge is a connection between any two elements in an integration and an edge condition lets you specify the conditions that must be met for control of an integration to pass to the task connected by the edge. For more information on edges and edge conditions, see Edges.

  1. Add an edge connection from the Salesforce trigger element to the Data Mapping element.
  2. Add an edge connection from the Data Mapping element to the Insert row to Cloud SQL Connector element with the following edge condition:
    OpportunityIsClosedOpportunityIsClosedOpportunityIsClosed = TRUE
  3. Add another edge connection from the Data Mapping element to the Cloud Pub/Sub Connector element with the following edge condition:
    OpportunityIsClosedOpportunityIsClosedOpportunityIsClosed = FALSE

Sample image showing the edge connections

Sample image showing the edge connections

Test the integration

To test the new integration:

  1. Click Test in the integration designer toolbar, and then select the Salesforce Trigger.
    The Test Integration dialog appears.
  2. Click Test integration.

Test the Cloud SQL task by logging in to the Salesforce instance and changing an opportunity status to "closed."

Test the Pub/Sub task by logging in to the Salesforce instance and changing another detail about the opportunity, but leave the status of the opportunity "open."

For more information about testing, see Test and publish integrations.

To verify the success of your integration: