---
schema_version: "1"
id: 7575b05e9445bbcc56e1ee40262fc51d7c95add3b22b6ecd6587514ad7d5b5f8
title: Salesforce Pub/Sub Connector 1.3 Examples
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/salesforce-pubsub-connector/1.3/salesforce-pubsub-connector-examples.md
canonical_url: https://docs.mulesoft.com/salesforce-pubsub-connector/1.3/salesforce-pubsub-connector-examples
source_site: docs.mulesoft.com
content_type: documentation
content_hash: f12b16d33833bff25a7775434eff719408fc132961f386ac85216adc8879a617
description: MuleSoft Documentation Site
release: "1.3"
latest: false
---
---
product: Salesforce Pub/Sub Connector
version: 1.3
---

# Salesforce Pub/Sub Connector 1.3 Examples

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

The following examples show several Mule flows for Salesforce Pub/Sub Connector:

- [Publish an Event](#publish-an-event)

- [Configure Publish Request Timeout](#publish-request)

- [Subscribe to a Channel](#subscribe-to-a-channel)

## Configure a Connection

To secure connections, you must specify the connection field values. To do this:

- [Create a configuration file for a connection.](#create-config-file)

- [Configure the connection global elements.](#configure-conn)

- [Configure a global element for the properties file.](#configure-global)

### Create a Configuration File for a Connection

Create a configuration file that includes properties for a connection:

1.  Create a file named `mule-app.properties` in the `/src/main/resources/` folder.

2.  In the `mule-app.properties` file, create a set of properties for the connection, similar to the
    ones that follow, replacing the bracketed text (including the brackets) with the correct values
    for your configuration:

    m4-config.username=<username within Salesforce Pub/Sub system> m4-config.password=<password for
    the username within Salesforce Pub/Sub system> m4-config.securityToken=<security token within
    Salesforce Pub/Sub system> m4-config.url=<endpoint representing your development environment>

    The properties used vary depending on the selected connection configuration.

For more information about creating a properties file, refer to
[Configuring Property Placeholders](https://docs.mulesoft.com/mule-runtime/latest/mule-app-properties-to-configure).

### Configure the Connection Global Elements

Configure global elements for connection:

1.  Create a new Mule project.

2.  In the **Mule Palette** view, click **Search in Exchange** and enter `Salesforce Pub/Sub`.

3.  Add **Salesforce Pub/Sub Connector** to the **Selected modules** section and click **Finish**.

4.  Click the **Global Elements** tab and click **Create**.

5.  Select **Connector Configuration > Salesforce Pub/Sub Config** and click **OK**.

6.  Enter the values to configure either Basic Authentication, OAuth v2.0, OAuth JWT, OAuth Username
    Password, or OAuth SAML. Note that the `Basic Authentication` connection type is only supported
    for Salesforce API v64.0 and earlier versions.

7.  Click the **Test Connection** button to ensure there is connectivity with the Salesforce Pub/Sub
    API. A successful message should pop up.

8.  Click **OK**.

9.  Open the HTTPS Listener config in **Global Element Configuration**.

10. Click the **TLS** tab and select **TLS Configuration > Edit inline**.

11. Specify the **Key Store Configuration** with the generated keystore details to enable HTTPS on
    this configuration.

12. Click **OK**.

### Configure a Global Element for the Properties File

Configure a global element for the `mule-app.properties` file so that Mule knows where to find it:

1.  Click the **Global Elements** tab and click **Create**.

2.  In the **Choose Global Type** dialog, select **Configuration properties** and click **OK**.

3.  In the **File** field, enter `mule.app.properties`.

4.  Click **OK**.

## Publish an Event

This example Mule flow publishes an event and uses the following operations:

- **HTTP Listener**  
  Accepts data from HTTP requests.

- **Transform Message**  
  Outputs the data in Java.

- **Publish event**  
  Publishes the given list of events to the specified event topic. Only high-volume platform events,
  including real-time event monitoring events and change data capture events, are allowed.

  Enter the following values:

  <table><colgroup><col> <col></colgroup><thead><tr><th>Field</th><th>Value</th></tr></thead><tbody><tr><td><p><strong>Topic</strong></p></td><td><div><div><p>Name of the topic used for message publishing, for example, <code>/event/gRPCMunitTestDoNotDelete__e</code></p></div></div></td></tr><tr><td><p><strong>Job Id</strong></p></td><td><div><div><p><code>payload</code></p></div></div></td></tr></tbody></table>

![Studio flow for the Publish event operation](/mulesoft/current/en-us/salesforce-pubsub-connector/1.3/_images/publish-an-event.png)

### XML for This Example

Paste this code into the Studio XML editor to quickly load the flow for this example into your Mule
app:

```xml
<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core"
	  xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:salesforce-pub-sub="http://www.mulesoft.org/schema/mule/salesforce-pub-sub" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/salesforce-pub-sub http://www.mulesoft.org/schema/mule/salesforce-pub-sub/current/mule-salesforce-pub-sub.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">

	<configuration-properties file="mule-app.properties"/>

	<salesforce-pub-sub:pubsub-config name="Salesforce_PubSub_Config" >
		<salesforce-pub-sub:basic-connection username="${m4-config.username}" password="${m4-config.password}" securityToken="${m4-config.securityToken}" url="${m4-config.url}"/>
	</salesforce-pub-sub:pubsub-config>

	<http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config" doc:id="3805c5f1-0f01-476a-a619-a03f34dadfdd" >
		<http:listener-connection host="0.0.0.0" port="8081" />
	</http:listener-config>
<flow name="mule-salesforce-pubsub-connector-publish-event-demo" doc:id="9e2df8f5-1b47-4a76-ac62-941c989cd93b" >
  <http:listener doc:name="Listener" doc:id="6e06a214-3112-40ef-8720-f730121aa5e0" config-ref="HTTP_Listener_config" path="/publish-event"/>
  <ee:transform>
    <ee:message>
      <ee:set-payload><![CDATA[%dw 2.0
        output application/java
        ---
        [{
          CreatedDate: 12334455,
          CreatedById: "123",
          Desc__c: "Something"
        },{
          CreatedDate: 12334456,
          CreatedById: "1234",
          Desc__c: "Something2"
        }
        ]]]>
      </ee:set-payload>
    </ee:message>
  </ee:transform>

  <salesforce-pub-sub:publish-event config-ref="Salesforce_PubSub_Config" topic="/event/gRPCMunitTestDoNotDelete__e"/>
</flow>
</mule>
```

## Configure Publish Request Timeout

This example shows how to configure the **Publish Request Timeout** and **Publish Request Time
Unit** parameters to control the timeout behavior for publish operations. This is useful when you
want to ensure that publish requests don’t wait indefinitely and have specific timeout requirements.
This example Mule flow configures timeout settings.

The key timeout configuration parameters are:

<table><colgroup><col> <col></colgroup><thead><tr><th>Field</th><th>Value</th></tr></thead><tbody><tr><td><p><strong>Publish Request Timeout</strong></p></td><td><div><div><p><code>60</code> (60 units of time before timeout)</p></div></div></td></tr><tr><td><p><strong>Publish Request Time Unit</strong></p></td><td><div><div><p><code>SECONDS</code> (timeout unit specification)</p></div></div></td></tr></tbody></table>

![Global element properties window for the Publish event operation with timeout configuration](/mulesoft/current/en-us/salesforce-pubsub-connector/1.3/_images/salesforce-pub-publish-timeout.png)

### XML for This Example

Paste this code into the Studio XML editor to quickly load the flow for this example into your Mule
app:

```xml
<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting"
	xmlns:tls="http://www.mulesoft.org/schema/mule/tls" xmlns:http="http://www.mulesoft.org/schema/mule/http"
	xmlns:os="http://www.mulesoft.org/schema/mule/os"
	xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xmlns:salesforce-pub-sub="http://www.mulesoft.org/schema/mule/salesforce-pub-sub" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/scripting http://www.mulesoft.org/schema/mule/scripting/current/mule-scripting.xsd http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/salesforce-pub-sub http://www.mulesoft.org/schema/mule/salesforce-pub-sub/current/mule-salesforce-pub-sub.xsd
http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd
http://www.mulesoft.org/schema/mule/os http://www.mulesoft.org/schema/mule/os/current/mule-os.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/tls http://www.mulesoft.org/schema/mule/tls/current/mule-tls.xsd">
	<salesforce-pub-sub:pubsub-config name="insecureSalesforce_PubSub_Config" doc:name="Salesforce PubSub Config"  >
		<salesforce-pub-sub:oauth-user-pass-connection consumerKey="&lt;CONSUMER_KEY&gt;" consumerSecret="&lt;CONSUMER_SECRET&gt;" username="&lt;USERNAME&gt;" password="&lt;USERNAME&gt;" securityToken="&lt;SECURITY_TOKEN&gt;" tokenEndpoint="&lt;TOKEN_ENDPOINT&gt;" host="&lt;GRPC_HOST&gt;" port="0000" publishRequestTimeout="60" >
		</salesforce-pub-sub:oauth-user-pass-connection>
	</salesforce-pub-sub:pubsub-config>

	<os:object-store name="replayObjectStore" doc:name="Object store"  entryTtlUnit="DAYS" expirationIntervalUnit="DAYS" entryTtl="1"/>


	<http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config"  >
		<http:listener-connection host="0.0.0.0" port="8081" />
	</http:listener-config>
	<flow name="ytaoka-salesforce-pubsublistenerFlow1"  initialState="started">
		<http:listener doc:name="Listener"  config-ref="HTTP_Listener_config" path="/publish"/>

	 <logger level="INFO" doc:name="Logger"  message="Before Publish" />
		<salesforce-pub-sub:publish-event config-ref="insecureSalesforce_PubSub_Config" topic="/event/gRPCMunitTestDoNotDelete__e">
        </salesforce-pub-sub:publish-event>
		<logger level="INFO" doc:name="Logger"  message="After Publish"/>
	</flow>
</mule>
```

## Subscribe to a Channel

This example Mule flow subscribes to a channel and uses the following operations:

- **Subscribe channel listener**  
  Subscribes to a streaming channel. This source provides channel-related notification settings for
  new events that occur after you subscribe.

  > [!NOTE] A channel must be published to Salesforce before a subscription to the channel is
  > created.

  Enter the following values:

  <table><colgroup><col> <col></colgroup><thead><tr><th>Field</th><th>Value</th></tr></thead><tbody><tr><td><p><strong>Channel name</strong></p></td><td><div><div><p>Name of the streaming channel to subscribe to, for example, <code>/event/gRPCMunitTestDoNotDelete__e</code></p></div></div></td></tr><tr><td><p><strong>Replay option</strong></p></td><td><div><div><p>One of the given implementations, for example, <code>Earliest</code>. For more information on how to use <code>Replay id from object store</code> in <strong>Replay option</strong>, refer to <a href="https://docs.mulesoft.com/salesforce-pubsub-connector/1.3/salesforce-pubsub-connector-studio#store-objectstore">Store the Replay ID in the Object Store</a>.</p></div></div></td></tr><tr><td><p><strong>Batch events size</strong></p></td><td><div><div><p>Total number of events included in a server batch. Lower values indicate small memory footprint with more server calls, while bigger values indicate bigger memory footprint with fewer API calls. A new batch of events is requested by the connector after the flow consumes the existing events, for example, <code>1000</code></p></div></div></td></tr></tbody></table>

- **Logger**  
  Shows the HTTP response from the **Subscribe channel listener** source

![Studio flow for the Subscribe channel listener source](/mulesoft/current/en-us/salesforce-pubsub-connector/1.3/_images/subscribe-to-a-channel.png)

### XML for This Example

Paste this code into the Studio XML editor to quickly load the flow for this example into your Mule
app:

```xml
<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core"
	  xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:salesforce-pub-sub="http://www.mulesoft.org/schema/mule/salesforce-pub-sub" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/salesforce-pub-sub http://www.mulesoft.org/schema/mule/salesforce-pub-sub/current/mule-salesforce-pub-sub.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">

	<configuration-properties file="mule-app.properties"/>

	<salesforce-pub-sub:pubsub-config name="Salesforce_PubSub_Config" >
		<salesforce-pub-sub:basic-connection username="${m4-config.username}" password="${m4-config.password}" securityToken="${m4-config.securityToken}" url="${m4-config.url}"/>
	</salesforce-pub-sub:pubsub-config>

	<http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config" doc:id="3805c5f1-0f01-476a-a619-a03f34dadfdd" >
		<http:listener-connection host="0.0.0.0" port="8081" />
	</http:listener-config>

	<flow name="mule-salesforce-pubsub-connector-subscribe-channel-demo" doc:id="4faf2bf8-e2af-43bc-bba8-d336761800dd" >
		<salesforce-pub-sub:subscribe-channel-listener channelName="/event/gRPCMunitTestDoNotDelete__e" config-ref="Salesforce_PubSub_Config" eventBatchSize="1000">
			<salesforce-pub-sub:replay-option >
				<salesforce-pub-sub:earliest />
			</salesforce-pub-sub:replay-option>
		</salesforce-pub-sub:subscribe-channel-listener>
		<logger level="INFO" doc:name="Logger" doc:id="21652e14-de84-4752-a9b9-871dc346befb" message="#[payload]"/>
	</flow>
</mule>
```

## See Also

- [Introduction to Anypoint Connectors](https://docs.mulesoft.com/connectors/introduction/introduction-to-anypoint-connectors)

- [Salesforce Help](https://help.salesforce.com)
