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:
- Create a PushTopic using Salesforce Developer Console.
- Reset the security token to authenticate with the Salesforce API.
- Configure the Inbound Endpoint in WSO2 Micro Integrator using the Visual Studio Code extension.
- 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:
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:
-
Login to your Salesforce Account. On the Home page, click the Setup icon (top right) and open Developer Console.
-
In the Developer Console, go to Debug → Open Execute Anonymous Window.
-
Paste the following Apex code into the Enter Apex Code window and click Execute.
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¶
-
Login to your Salesforce Account. Click the Settings icon (top right corner of the Home page).
-
Navigate to Reset My Security Token and click Reset Security Token.
Step 3: Configure Inbound Endpoint using WSO2 Micro Integrator VS Code Extension¶
-
Follow Create Integration Project steps to set up your project.
-
Go to the Add Artifact section and select Event Integration.
-
Create a Salesforce Inbound Endpoint.
-
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>
-
Submit the configuration.
-
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 a Drop Mediator to the sequence to drop the messages after logging.
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.
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.
You can also use the Salesforce REST Connector example to insert data:
- Save the following payload as
data.json
:
{
"sObject": "Account",
"fieldAndValue": {
"name": "Manager",
"description": "This Account belongs to WSO2"
}
}
- 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"}}