Nav

To Work with Salesforce Topics

Topics group Salesforce records into common themes. The Salesforce connector allows a Mule app to receive notifications if one or multiple Salesforce records meet the criteria used to define the topic.

To Create or Publish a Topic

Before you can receive any events for Salesforce changes associated with a topic, you must first create a topic (a PushTopic). A PushTopic is a special object in Salesforce that binds a name (the topic’s name) and Salesforce Object Query Language (SOQL) query together. Once a PushTopic is created, you can subscribe to it by using its name.

In Design Center, you can either use the Create (create) or Publish Topic (publish-topic) operation to create a topic. Example of the required fields for these operations:

  • Topic Name: AccountUpdates

  • Query: SELECT Id, Name FROM Account

Example in XML for publish-topic:

<sfdc:publish-topic name="AccountUpdates" query="SELECT Id, Name FROM Account"/>

Alternatively, in Salesforce you might create a topic by executing code like this from an Enter Apex Code window, accessible through your system logs:


         
      
1
2
3
4
5
6
7
PushTopic pushTopic = new PushTopic();
pushTopic.ApiVersion = 23.0;
pushTopic.Name = 'AllAccounts';
pushTopic.Description = 'All records for the Account object';
pushtopic.Query = 'SELECT Id, Name FROM Account';
insert pushTopic;
System.debug('Created new PushTopic: '+ pushTopic.Id);

To Subscribe to a Topic

After you create a topic, you can start receiving events by subscribing to the topic. To do so, you add the Subscribe Topic (subscribe-topic) or a Replay Topic (replay-topic) trigger to your flow. The trigger acts as an inbound endpoint. Every time the subscription receives an event, the trigger executes the rest of the flow in your Mule app. In the case of the XML example below, it prints a message to the log at INFO level.

In Design Center, you use Subscribe Topic or Replay Topic operations for the Salesforce connector as the trigger.

In XML, you use subscribe-topic or replay-topic as the trigger:


         
      
1
2
3
4
5
6
<flow name="accountUpdatesSubscription">
    <!-- INBOUND ENDPOINT -->
    <sfdc:subscribe-topic topic="AccountUpdates"/>
    <!-- REST OF YOUR FLOW -->
    <logger level="INFO" message="Received an event for Salesforce Object ID #[map-payload:Id]"/>
</flow>

To Replay Events from a Topic

A subscriber can specify which events to receive, such as all events within the retention window or those that start after a particular event. The default is to receive only new events sent after subscribing. Events outside the 24-hour retention period are discarded.

The Replay Topic (replay-topic) provides these options:

  • All (ALL): Subscriber receives all events, including past events that are within the 24-hour retention period and new events sent after subscription.

  • Only New (ONLY_NEW): Subscriber receives new events that are broadcast after the client subscribes.

  • From Replay ID (FROM_REPLAY_ID): Subscriber receives all events after the specified event replayId.

Resume From the Last Replay ID: An option that allows for automatic replay of stored events, based on the Replay ID of the last event processed by the connector. This functionality can be useful in cases when the connector stopped listening for some reason, such as a server shutdown or dropped connection. If the stored Replay ID is outside the 24-hour retention period, your replay option determines what events to replay.

In this XML example, the replay-topic acts like an inbound endpoint for the Logger message:


         
      
1
2
3
4
5
6
<flow name="accountUpdatesReplay">
    <!-- INBOUND ENDPOINT -->
    <sfdc:replay-topic topic="AccountUpdates" replayId="1" replayOption="ALL" autoReplay="true"/>
    <!-- REST OF YOUR FLOW -->
    <logger level="INFO" message="Replayed events: #[payload]"/>
</flow>

If ALL or ONLY_NEW replay option is selected, then the replayId value is ignored.