# Salesforce Streaming

## **What is streaming** <a href="#salesforcestreamingconnector-whatisstreaming" id="salesforcestreamingconnector-whatisstreaming"></a>

Streaming is a method used to transfer data over a network as a continuous flow. One of its main benefits is that it allows the data recipients to use it in real time, without having to wait until the complete data set has been uploaded on their computers.

## **What is the Salesforce Streaming API** <a href="#salesforcestreamingconnector-whatisthesalesforcestreamingapi" id="salesforcestreamingconnector-whatisthesalesforcestreamingapi"></a>

Salesforce has a set of data APIs that can be used to manipulate the App’s data. Among them, the Streaming API is used to set notifications triggered by data changes. The notifications are sent from a server to a client.

The Salesforce Streaming API follows the Publish – Subscribe model. In it, users subscribe to available channels that broadcast specific data changes. These data changes are defined by SOQL queries. For example, a channel can notify its users about changes in Account’s Emails.

The main advantage of this model is that it eliminates pooling and therefore, it is useful for communicating very frequent changes - practically producing real time integration.

Additionally, the API’s use of long polling or Comet Programming technique, reduces the number of requests that return no-data.

### **Main Characteristics of the Salesforce Streaming API** <a href="#salesforcestreamingconnector-maincharacteristicsofthesalesforcestreamingapi" id="salesforcestreamingconnector-maincharacteristicsofthesalesforcestreamingapi"></a>

Salesforce API has many important characteristics that define its behavior. Among them:

1. **Communication type:** the API is based on asynchronous communication.
2. **Bayeux Protocol:** the API uses this protocol to transmit asynchronous messages.
3. **CometD:** the API uses this scalable event routing bus for message transmission. It is based on Ajax communication and the Bayeux protocol. The method opens a single persistent connection from the client to the server. Events are then incrementally handled and interpreted on the Client’s side, every time a new event arrives.
4. **Long polling or Comet programming:** this method emulates an information push from server to client. As it waits until there is some data to be sent, it doesn’t send no-data notifications.

### **DBSync Salesforce Streaming Connector** <a href="#salesforcestreamingconnector-thedbsyncsalesforcestreamingconnector" id="salesforcestreamingconnector-thedbsyncsalesforcestreamingconnector"></a>

It is within the context of the Salesforce Streaming API that, DBSync developed a connector that can be used specifically for real time integration. The connector is known as Salesforce Streaming Connector.

There are two important points to consider when using the Salesforce Streaming Connector. First, the process should run as continuously as possible, without much interruption. Second, how to schedule the process. We will explain the use of this connector with an example.

In this example we will connect Salesforce table Accounts to a MySQL table Accounts. The steps are:

1. Create a new project.
2. Create a Salesforce Streaming Connector and a Database Connector.
3. Create a new process.
4. Create a new workflow.
5. Create a new trigger, rule and map.
6. Create a schedule.
7. Run the process.

As the steps are similar to any DBSync process creation, we will concentrate on the steps with specific differences, namely steps 2, 4 and 5.

### **Create a Salesforce Streaming Connector** <a href="#salesforcestreamingconnector-createasalesforcestreamingconnector" id="salesforcestreamingconnector-createasalesforcestreamingconnector"></a>

In order to create a Salesforce Streaming connector, simply press the button *Create New Connector*, and select the type *Salesforce Streaming Connector*.

<figure><img src="https://docs.mydbsync.com/~gitbook/image?url=https%3A%2F%2Fhelp.mydbsync.com%2Fdocs%2Fdownload%2Fattachments%2F25428218%2Fimage2018-5-4_3-21-20.png%3Fversion%3D1%26modificationDate%3D1525382519000%26api%3Dv2&#x26;width=300&#x26;dpr=4&#x26;quality=100&#x26;sign=a84f5fbc2e0a0b362748fdcf8ff678d8abfebe1fefa351369f8967c1fc8db19c" alt=""><figcaption></figcaption></figure>

### **Create a Schedule** <a href="#salesforcestreamingconnector-createaschedule" id="salesforcestreamingconnector-createaschedule"></a>

As we mentioned earlier, we want to create a process that runs as continuously as possible. However, DBSync cannot detect if the process has stopped for any reason; and thus, it cannot restart it automatically.

In order to solve this problem, we need to set up the schedule at every one minute interval. The cron expression for this is “0/1 0/1 1/1 ?\*”. Alternatively, we can simply select minutes and specify “1”.

<figure><img src="https://docs.mydbsync.com/~gitbook/image?url=https%3A%2F%2Fhelp.mydbsync.com%2Fdocs%2Fdownload%2Fattachments%2F25428218%2Fimage2018-5-4_3-21-48.png%3Fversion%3D1%26modificationDate%3D1525382519000%26api%3Dv2&#x26;width=300&#x26;dpr=4&#x26;quality=100&#x26;sign=6ac0038c4101543ebad88e7e68951a042e327f0124a7c9a41a48bb9f46ff8346" alt=""><figcaption></figcaption></figure>

### **Create a Trigger** <a href="#salesforcestreamingconnector-createatrigger" id="salesforcestreamingconnector-createatrigger"></a>

As we are transferring data from Salesforce to MySQL, we need to create a trigger that contains a query. This query must include the ID of the Salesforce table - in our case Accounts. The query must not include joins or aggregate functions. Besides, the WHERE clause must not include lookup fields.

<figure><img src="https://docs.mydbsync.com/~gitbook/image?url=https%3A%2F%2Fhelp.mydbsync.com%2Fdocs%2Fdownload%2Fattachments%2F25428218%2Fimage2018-5-4_3-22-34.png%3Fversion%3D1%26modificationDate%3D1525382519000%26api%3Dv2&#x26;width=300&#x26;dpr=4&#x26;quality=100&#x26;sign=0c2e1430f0b68dabf720cde8161d9eeaf2261767bed3bec911f6d4405c40b6a8" alt=""><figcaption></figcaption></figure>

### **Create a New Rule** <a href="#salesforcestreamingconnector-createanewrule" id="salesforcestreamingconnector-createanewrule"></a>

When we create a new rule, we must make sure to map the ID from Salesforce to the MySQL table’s ID.

<figure><img src="https://docs.mydbsync.com/~gitbook/image?url=https%3A%2F%2Fhelp.mydbsync.com%2Fdocs%2Fdownload%2Fattachments%2F25428218%2Fimage2018-5-4_3-22-55.png%3Fversion%3D1%26modificationDate%3D1525382519000%26api%3Dv2&#x26;width=300&#x26;dpr=4&#x26;quality=100&#x26;sign=34c4083a675c84ecc8556fc5d428468c4a28fb80bdf79bfb3785621d1699a805" alt=""><figcaption></figcaption></figure>

### **Seeing the Results** <a href="#salesforcestreamingconnector-seeingtheresults" id="salesforcestreamingconnector-seeingtheresults"></a>

The advantages of the Salesforce Streaming Connector can be easily seen by changing the value of, for example, the website of an account: the change is almost immediately reflected in our MySQL database.

<figure><img src="https://docs.mydbsync.com/~gitbook/image?url=https%3A%2F%2Fhelp.mydbsync.com%2Fdocs%2Fdownload%2Fattachments%2F25428218%2Fimage2018-5-4_3-23-22.png%3Fversion%3D1%26modificationDate%3D1525382519000%26api%3Dv2&#x26;width=300&#x26;dpr=4&#x26;quality=100&#x26;sign=8ceccda6b4fe4d4dc3e6922a70e554fde4dd9e8e36a5d1acfa4d7fbb1d0df3bf" alt=""><figcaption></figcaption></figure>

<figure><img src="https://docs.mydbsync.com/~gitbook/image?url=https%3A%2F%2Fhelp.mydbsync.com%2Fdocs%2Fdownload%2Fattachments%2F25428218%2Fimage2018-5-4_3-23-45.png%3Fversion%3D1%26modificationDate%3D1525382519000%26api%3Dv2&#x26;width=300&#x26;dpr=4&#x26;quality=100&#x26;sign=8bd784f5466994489078515b6612c990ae3b1b788d046e61160eb32b98f89605" alt=""><figcaption></figcaption></figure>

## **Conclusion** <a href="#salesforcestreamingconnector-conclusion" id="salesforcestreamingconnector-conclusion"></a>

DBSync’s Salesforce Streaming Connector allows us to link Salesforce to another application in almost real time.

However, there are few aspects to consider - namely, the setting up of the schedule with a repeating frequency of one minute; the limitations on the trigger’s query; and, the mapping of IDs.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.mydbsync.com/cloud-workflow/connectors/salesforce-streaming.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
