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

# Salesforce Pub/Sub Connector 1.0 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)

- [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.

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.0/_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>
```

## 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.0/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.0/_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)
