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:

For sample workflows on importing 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 Salesforce.com 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 “write-to-Salesforce.com” 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 “write-to-Salesforce.com” feature, you can streamline the process and focus on building visualizations of your query results via Reports and Dashboards on the Salesforce.com organization.

Continue to the following topics:


Prerequisites

Support

SFDC output supports these authentication types:

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

  1. Go to Setup > Apps > App Manage.

  2. Select New Connected App.


    The steps may vary depending on the version of Salesforce you are running. In Spring 19 classic UI: Setup > Build > Create > Apps > Connected Apps > New.


  3. Navigate to Setup > Build > Create (Apps), and validate all your connected apps:


  4. Select your app name to go to the page where you can view and manage all information about your connected app.

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


  6. 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 login.salesforce.com as the login URL. Remove unnecessary letters from Login URL parameter.




5. Select Continue.

6. 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:

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.



Integration Parameters for Salesforce


ParameterDescription
ObjectSalesforce.com Object
Mode
  • 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 Salesforce.com 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 Salesforce.com 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 Salesforce.com 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.


Optionally Configure Export Results in Workflow

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

Learn more at Using Workflows to Export Data with the TD Toolbelt.

Example Workflow for Salesforce Export


timezone: UTC

schedule:
  daily>: 02:00:00

sla:
  time: 08:00
  +notice:
    mail>: {data: Treasure Workflow Notification}
    subject: This workflow is taking long time to finish
    to: [meg@example.com]

_export:
  td:
    dest_db: dest_db
    dest_table: dest_table

+prepare_table:
  td_ddl>:
  create_databases: ["${td.dest_db}"]
  create_tables: ["${td.dest_table}"]
  database: ${td.dest_db}

+load:
  td_load>: config/daily_load.yml
  database: ${td.dest_db}
  table: ${td.dest_table}