Skip to content

Salesforce Inbound Endpoint Push Topic Example

About PushTopic

A PushTopic lets you define a SOQL query and receive event notifications when changes occur to the data matching that query. It provides a powerful way to monitor Salesforce records in near real-time. When a record is created, updated, deleted, or undeleted, a corresponding notification is published to the defined topic, which the Inbound Endpoint in WSO2 Micro Integrator can consume.

What you'll build

This guide walks you through the process of setting up a Salesforce Inbound Endpoint that listens to changes in Salesforce records using a PushTopic.

You will:

  1. Create a PushTopic using Salesforce Developer Console.
  2. Reset the security token to authenticate with the Salesforce API.
  3. Configure the Inbound Endpoint in WSO2 Micro Integrator using the Visual Studio Code extension.
  4. Run and test the integration to receive real-time notifications.

The inbound endpoint acts as a message receiver and injects events into an integration sequence. In this example, we simply log the message, but you can extend this to perform any complex mediation logic using WSO2 Micro Integrator mediators.

In this example, we will use the Account object in Salesforce to demonstrate the PushTopic functionality. When an Account record is created, updated, deleted, or undeleted, the WSO2 Inbound Endpoint will receive notifications and process them accordingly. For a visual representation of the integration, refer to the diagram below:

Salesforce Inbound Endpoint

Step 1: Creating a PushTopic

The PushTopic object includes a SOQL query that defines which data changes will trigger events. Here’s how you can create one using the Salesforce Developer Console:

  1. Login to your Salesforce Account. On the Home page, click the Setup icon (top right) and open Developer Console.

    Open the Developer Console.

  2. In the Developer Console, go to DebugOpen Execute Anonymous Window.

    Open the Anonymous Window.

  3. Paste the following Apex code into the Enter Apex Code window and click Execute.

    Enter Apex code.

PushTopic pushTopic = new PushTopic();
pushTopic.Name = 'Account';
pushTopic.Query = 'SELECT Id, Name FROM Account';
pushTopic.ApiVersion = 37.0;
pushTopic.NotifyForOperationCreate = true;
pushTopic.NotifyForOperationUpdate = true;
pushTopic.NotifyForOperationUndelete = true;
pushTopic.NotifyForOperationDelete = true;
pushTopic.NotifyForFields = 'Referenced';
insert pushTopic;

This code sets up a PushTopic to listen for all changes on the Salesforce Account object. Once created, Salesforce will send notifications to the WSO2 Inbound Endpoint whenever an Account record changes.

Step 2: Reset Security Token

  1. Login to your Salesforce Account. Click the Settings icon (top right corner of the Home page).

    Select Settings

  2. Navigate to Reset My Security Token and click Reset Security Token.

    Reset Security Token

Step 3: Configure Inbound Endpoint using WSO2 Micro Integrator VS Code Extension

  1. Follow Create Integration Project steps to set up your project.

  2. Go to the Add Artifact section and select Event Integration.

    Add Inbound Endpoint

  3. Create a Salesforce Inbound Endpoint.

    Create Salesforce Inbound Endpoint

  4. Fill in the form with the following values:

    • Name: SalesforceInboundEP
    • Injecting Sequence Name: test
    • Error Sequence Name: test
    • Polling Interval: 100
    • Salesforce Object: /topic/Account
    • Package Version: 37.0
    • User Name: <USERNAME>
    • Password: <SALESFORCE_PASSWORD><SECURITY_TOKEN>
    • Login Endpoint: https://login.salesforce.com
    • SOAP API Version: 22.0
    • Wait Time: 5000
    • Connection Timeout: 20000
    • Execute sequentially and Coordination: select
    • Replay: deselect
    • Event ID File Path: <FILE_PATH>
  5. Submit the configuration.

    Inbound Endpoint Configuration

  6. Add a Log Mediator to the sequence to log the incoming messages. and tick the Append Payload option to include the payload in the log.

    Add Log Mediator

  7. Add a Drop Mediator to the sequence to drop the messages after logging.

    Add Drop Mediator

Step 4: Deploy ,Run and Test the Integration

Run the Integration

In order to deploy and run the project, refer the build and run guide or simply use the Run button in the Visual Studio Code extension to run the integration.

Deploy and Run the Integration

You can further refer the application deployed through the CLI tool. See the instructions on managing integrations from the CLI.

Testing the Integration

You can manually insert records into Salesforce via Salesforce UI or use the Salesforce REST API to insert records.

Insert Records into Salesforce

You can also use the Salesforce REST Connector example to insert data:

  1. Save the following payload as data.json:
{
    "sObject": "Account",
    "fieldAndValue": {
        "name": "Manager",
        "description": "This Account belongs to WSO2"
    }
}
  1. Invoke the API using the following curl command:
curl -X POST -d @data.json http://localhost:8280/salesforcerest --header "Content-Type:application/json"

Expected Output

After inserting a record, you should see a log entry in the WSO2 Micro Integrator console similar to the following:

To: , MessageID: urn:uuid:2D8F9AFA30E66278831587368713372, Direction: request, Payload: {"event":{"createdDate":"2020-04-20T07:45:12.686Z","replayId":4,"type":"created"},"sobject":{"Id":"0012x0000048j9mAAA","Name":"Manager"}}