You can connect Datastream to a Salesforce instance to replicate
historical data and change events for analytics and data integration.
Salesforce is a cloud-based customer relationship management platform where
each instance is often referred to as a *Salesforce organization* or
*Salesforce org*.

When setting up a Salesforce source in Datastream, review the
[key terms](https://docs.cloud.google.com/datastream/docs/sources-salesforce#key-terms), [replication behavior](https://docs.cloud.google.com/datastream/docs/sources-salesforce#behavior), [supported editions
and API versions](https://docs.cloud.google.com/datastream/docs/sources-salesforce#versions), [best practices](https://docs.cloud.google.com/datastream/docs/sources-salesforce#salesforcebestpractices), and
[known limitations](https://docs.cloud.google.com/datastream/docs/sources-salesforce#known-limitations).

## Key terms

Salesforce operates using objects, records and fields:

- An **object** is a class entity, and is similar to a table in relational databases nomenclature. Objects can be standard or custom. Standard objects are included in Salesforce by default, while custom objects are created by users to store data specific to their use-cases.
- A **record** is a specific instance of an object, similar to a row in relational databases.
- A **field** is a specific attribute of an object, similar to a column in relational databases.

## Behavior

The Salesforce source support in Datastream relies upon the REST
and Bulk 2.0 APIs. Salesforce polls for source changes based on the interval
that you set to allow control over the API usage.

When replicating data from a Salesforce source, the following behavior is
observed:

- Replicateable and queryable standard objects which either have the `SystemModstamp` field or the `LastModifiedDate` can be replicated. For an object to be replicateable, it needs to support the `getUpdated()` and `getDeleted()` API calls. For more information, see [API Calls for Data Replication](https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/calls_for_data_replication.htm) in Salesforce documentation.
- Custom objects can be replicated.
- If configured, all historical data is replicated for included objects.
- All changes, such as inserts, updates, and deletes from the specified objects are replicated.
- Datastream polls for changes according to the configured polling interval. This is reflected in the stream's data freshness metric. The metric can grow up to the configured polling interval value and reflects the time passed from the most recent poll.

## Versions

Datastream supports the following Salesforce editions:

- Pro Suite
- Developer
- Professional
- Enterprise
- Unlimited

Datastream uses the Salesforce API version 61.0.

For more information about available Salesforce editions, see the
[Salesforce documentation](https://help.salesforce.com/s/articleView?id=xcloud.overview_edition.htm&type=5).

## Best practices

This section describes recommended best practices for configuring your Salesforce
source for use with Datastream.

### Manage API quota usage

Salesforce imposes limits on the number of API requests that can be made in a
24-hour rolling window. Exhausting this quota is a common challenge when
replicating data from Salesforce.

You can configure the polling interval in Datastream to reduce the
number of API requests made to Salesforce. While a shorter polling interval
enhances data freshness, it also increases the API quota usage. We recommend
setting a polling interval that balances your chosen data freshness with
the constraints of your API quota to ensure sustainable data replication. If
needed, you can increase the global API request quota in Salesforce.

## Known limitations

Known limitations for using Salesforce as a source include:

- Only queryable and replicateable objects are supported.
- [Compound fields](https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/compound_fields.htm) are replicated as flattened fields.
- Up to 600,000 deletes per minute are supported (Salesforce limitation).
- Streams are limited to 3000 objects.
- Calculated fields (also known as *formulas*) are only partially supported.
  Replication of calculated fields is subject to the following constraints:

  - Cross-table references aren't supported.
  - Non-deterministic functions (such as `NOW()` or `TODAY()`) aren't supported, as Datastream can't determine when the values of these fields change.
  - Only a specific set of allowed functions is supported. If a calculated field uses any function outside of this list, the field isn't replicated.

  The following list shows the supported functions:
  - **Logical:** `AND`, `OR`, `NOT`, `IF`, `CASE`, `ISNULL`, `ISBLANK`, `BLANKVALUE`, `ISPICKVAL`
  - **Math:** `ABS`, `CEILING`, `MCEILING`, `FLOOR`, `MFLOOR`, `ROUND`, `MOD`, `SQRT`, `EXP`, `LN`, `LOG`, `MAX`, `MIN`
  - **Text:** `BEGINS`, `BR`, `CONTAINS`, `FIND`, `HYPERLINK`, `INCLUDES`, `LEFT`, `LEN`, `LOWER`, `LPAD`, `MID`, `RPAD`, `RIGHT`, `SUBSTITUTE`, `TEXT`, `TRIM`, `UPPER`, `VALUE`
  - **Date and time:** `DATE`, `DATEVALUE`, `DATETIMEVALUE`, `DAY`, `MONTH`, `YEAR`, `HOUR`, `MINUTE`, `SECOND`, `MILLISECOND`, `WEEKDAY`, `TIMEVALUE`, `ADDMONTHS`
  - **Other:** `REGEX`
- Stream recovery isn't supported.

## What's next

- Learn how to [configure a Salesforce source](https://docs.cloud.google.com/datastream/docs/configure-salesforce-org) for use with Datastream.