You can connect Salesforce with Treasure Data for greater control over your Salesforce data and better integration with the other business applications in your marketing and sales operations stack. Integrating Salesforce with Treasure Data makes it easy to:

  • Add new features to Salesforce. For example, you can prevent churn by tracking web usage and receiving alerts when customers’ product usage declines.

  • Use Salesforce data to improve other parts of your marketing stack. For example, you can increase your Facebook Ads ROI by automatically removing new customers from your Facebook Custom Audiences.

For sample workflows on exporting data from Salesforce, go to Treasure Boxes.

If you don’t have a Treasure Data account yet, contact us so that we can get you set up.

A front-end application streams data to be collected in Treasure Data via Log/data collector daemon or Mobile SDKs. You can also bulk import your data using Bulk Import from the CLI. A scheduled query is setup in Treasure Data to run periodically on the data and write the result of each query execution into your Object. The following is a fairly common architecture, for example:

Ranking: What are the “Top N of X?”

Every social/mobile application calculates the “top N of X” (ex: top 5 movies watched today). Treasure Data already handles the raw data warehousing; the “” feature enables Treasure Data to find the “top N” data as well.

Dashboard Application

If you’re a data scientist, you need to keep track of a range of metrics every hour/day/month and make them accessible via visualizations. Using this “” feature, you can streamline the process and focus on building visualizations of your query results via Reports and Dashboards on the organization.

Continue to the following topics:


  • Basic knowledge of Treasure Data, including the TD Toolbelt.

  • organization and username, password, and security token for API integration.

  • You have “API Enabled” permission.

  • Target Object should exist with read and write permissions.


SFDC output supports these authentication types:

  • Credential

  • Session

Use the TD Console to Create Your Connection

Create a New Connection

Connecting to Salesforce using the TD Console is quick and easy. Alternatively, create a Salesforce connection using the command line. The export integration supports credentials; you need a client ID and client secret to authenticate using credentials.

Allow TD to Access Salesforce using Salesforce

These instructions guide you to locate the client ID and client secret that is necessary to authenticate using credentials.

This is the guide for Lightning Experience UI.

  1. Go to Setup > Apps > App Manager.

  2. Select New Connected App.

  3. Set some values and check Enable OAuth Settings. Then, grant OAuth permission scope.

  4. Click Save. Activation can take up to 10 minutes.
  5. Go to Setup > Apps > App Manager.
  6. Locate the connected app, click , and then select View.

  7. Write down or copy your Consumer Key (client_id) and Consumer Secret (client_secret).

  8. For secure account access, get a Salesforce Security Token. If you don’t have a security token, go to Account > Settings > Reset My Security Token and select Reset Security Token. You’ll receive your Security Token by email.

    In Spring 19 classic UI: My account > My Settings > Personal > Reset My Security Token.

Create New Connection in TD Console

  1. Open TD Console.

  2. Navigate to Integrations Hub > Catalog.

  3. Search for Salesforce.

    1. To authenticate with your credentials, enter your username (your email) and password, as well as your Client ID, Client Secret, and Security Token.

    2. In the dialog box, enter as the login URL. Remove unnecessary letters from Login URL parameter.

  4. Select Continue.

  5. Give your connection a descriptive name and select Create Connection.

Validate Your Salesforce Connection

To validate the user permission, make sure to use Salesforce to validate:

  • Authority: check the Salesforce export integration connection steps.

  • Allowed access to Salesforce from Treasure Data: sometimes configuring this requires knowing and configuring your TD static IP address. Please contact support if you require the static IP address information.

Without properly configured authority and access, you might encounter access restriction errors. For example:

Response not 2xx: 
400 Bad Request {"error":"invalid_grant","error_description":"authentication failure"}

Define your Query

Select a database and table from the popup menus. Enter your query and select Output results.

To avoid any issues with result export, define column aliases in your query such that resulting column names from the query match the Salesforce field names for default fields and API names (usually ending with __c) for custom fields.

  1. Complete the instructions in Creating a Destination Integration.
  2. Navigate to Data Workbench > Queries.

  3. Select a query for which you would like to export data.

  4. Run the query to validate the result set.

  5. Select Export Results.

  6. Select an existing integration authentication.
  7. Define any additional Export Results details. In your export integration content review the integration parameters.
    For example, your Export Results screen might be different, or you might not have additional details to fill out:
  8. Select Done.

  9. Run your query.

  10. Validate that your data moved to the destination you specified.

Integration Parameters for Salesforce

ParameterDescription Object
  • The append mode is the default that is used when no mode option is provided in the URL. In this mode, the query results are appended to the object.
  • With the truncate mode, the system first truncates the existing records in the Object and moves them into the Trashbin, then inserts the query results.
  • With the update mode, a row is inserted unless it would cause a duplicate value in the external key columns specified in the “unique” parameter. In such a case, an update is performed instead. The “unique” parameter is required with this mode and must be defined as an external key when used with the update mode.
    With the update mode, a row is inserted unless it would cause a duplicate value in the external key columns specified in the “unique” parameter. In such a case, an update is performed instead. The “unique” parameter is required with this mode and must be defined as an external key when used with the update mode.
Concurrency mode

The concurrency_mode option controls how the data is uploaded to the organization. The default mode is parallel.

With the parallel method, data is uploaded in parallel. This is the most reliable and effective method for most situations.

if you see “UNABLE_TO_LOCK_ROW” in an error message, try concurrency_mode=serial instead.

Retry LimitThis option sets the number of attempts made to write the result to the configured destination, if errors occur. If the export fails more than the set number of retries, the query fails.
The default number of retries is retry=2
Batch sizeSplits the records in the result of a query in chunks of 10000 records by default and bulk uploads one chunk at a time. 

Example Query

SELECT identifier_type, identifier
FROM table my_table

Optionally Schedule the Query Export Jobs

You can use Scheduled Jobs with Result Export to periodically write the output result to a target destination that you specify.

1. Navigate to Data Workbench > Queries.
2. Create a new query or select an existing query.
3. Next to Schedule, select None.

4. In the drop-down, select one of the following schedule options:

Drop-down ValueDescription
Custom cron...

Review Custom cron... details.

@daily (midnight)Run once a day at midnight (00:00 am) in the specified time zone.
@hourly (:00)Run every hour at 00 minutes.
NoneNo schedule.

Custom cron... Details

Cron Value


0 * * * *

Run once an hour.

0 0 * * *

Run once a day at midnight.

0 0 1 * *

Run once a month at midnight on the morning of the first day of the month.


Create a job that has no scheduled run time.

 *    *    *    *    *
 -    -    -    -    -
 |    |    |    |    |
 |    |    |    |    +----- day of week (0 - 6) (Sunday=0)
 |    |    |    +---------- month (1 - 12)
 |    |    +--------------- day of month (1 - 31)
 |    +-------------------- hour (0 - 23)
 +------------------------- min (0 - 59)

The following named entries can be used:

  • Day of Week: sun, mon, tue, wed, thu, fri, sat.

  • Month: jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec.

A single space is required between each field. The values for each field can be composed of:

Field ValueExampleExample Description

A single value, within the limits displayed above for each field.

A wildcard ‘*’ to indicate no restriction based on the field. 

‘0 0 1 * *’ Configures the schedule to run at midnight (00:00) on the first day of each month.
A range ‘2-5’, indicating the range of accepted values for the field.‘0 0 1-10 * *’ Configures the schedule to run at midnight (00:00) on the first 10 days of each month.
A list of comma-separated values ‘2,3,4,5’, indicating the list of accepted values for the field.

0 0 1,11,21 * *’

Configures the schedule to run at midnight (00:00) every 1st, 11th, and 21st day of each month.
A periodicity indicator ‘*/5’ to express how often based on the field’s valid range of values a schedule is allowed to run.

‘30 */2 1 * *’

Configures the schedule to run on the 1st of every month, every 2 hours starting at 00:30. ‘0 0 */5 * *’ configures the schedule to run at midnight (00:00) every 5 days starting on the 5th of each month.
A comma-separated list of any of the above except the ‘*’ wildcard is also supported ‘2,*/5,8-10’‘0 0 5,*/10,25 * *’Configures the schedule to run at midnight (00:00) every 5th, 10th, 20th, and 25th day of each month.
5.  (Optional) You can delay the start time of a query by enabling the Delay execution.

Execute the Query

Save the query with a name and run, or just run the query. Upon successful completion of the query, the query result is automatically imported to the specified container destination.

Scheduled jobs that continuously fail due to configuration errors may be disabled on the system side after several notifications.

Optionally Configure Export Results in Workflow

Within Treasure Workflow, you can specify the use of this data connector to export data.

Learn more at Exporting Data with Parameters.

Example Workflow for Salesforce Export

timezone: UTC

  daily>: 02:00:00

  time: 08:00
    mail>: {data: Treasure Workflow Notification}
    subject: This workflow is taking long time to finish
    to: []

  td>: queries/sample.sql
  database: database_name
  result_connection: authentication_name
    object: object_name
    mode: append
    concurrency_mode: parallel
    retry: 2
    split_records: 10000  

  • No labels