Salesforce to Redshift

This page provides you with key information on how to extract data from Salesforce’s backend and load it into Amazon Redshift. (If this manual process is a bit more involved than you’d prefer, check out Stitch, which can do all the heavy lifting for you in just a few clicks.)

Pulling Data Out of Salesforce

The first step of getting your Salesforce data into AWS Redshift is actually pulling that data off of Salesforce’s servers. We’ll focus on CRM and customer data here, as many of Salesforce’s other products have their own APIs as well (e.g. see Pardot to Redshift for more details on how to get marketing automation data into Redshift).

Salesforce has a lot of APIs. Here’s a list from their helpdesk post about which API to use:

Screen Shot 2015-11-06 at 1.17.29 AM

Reading that helpdesk post is a great place to link your use case to an API that makes sense for you. In this post, we’ll use the REST API to provide examples, but you can get the same information using other protocols (including streaming for real-time receipt of data).

When using the REST API, you’ll most likely write SOQL (Salesforce Object Query Language) queries that return the specific records (i.e. Accounts, Leads, Tasks, etc) you’re looking for.

Sample Salesforce Data

The Salesforce REST API can return JSON- or XML-formatted data depending on your preference. Below is an example of the kind of response you might see when querying for a list of Accounts.

    "done" : true,
    "totalSize" : 14,
    "records" : 
            "attributes" : 
                "type" : "Account",    
                "url" : "/services/data/v20.0/sobjects/Account/001D000000IRFmaIAH"  
            "Name" : "Test 1"
            "attributes" : 
                "type" : "Account",    
                "url" : "/services/data/v20.0/sobjects/Account/001D000000IomazIAB"  
            "Name" : "Test 2"



Preparing the Salesforce Data for Redshift

Here’s the tricky part: you need to map the data that comes out of each SOQL API request into a schema that can be inserted into a Redshift database. This means that, for each value in the response, you need to identify a predefined datatype (i.e. INTEGER, DATETIME, etc.) and build a table that can receive them. The Salesforce API documentation can give you a good sense of what fields will be provided about each object, along with their corresponding datatypes.

Inserting Salesforce Data into Redshift

Once you have identified all of the columns you will want to insert, you can use the CREATE TABLE statement in Redshift to create a table that can receive all of this data.

With a table built, it may seem like the easiest way to add your data (especially if there isn’t much of it), is to build INSERT statements to add data to your Redshift table row-by-row. If you have any experience with SQL, this will be your gut reaction. But beware! Redshift isn’t optimized for inserting data one row at a time, and if you have any kind of high-volume data being inserted, you would be much better off loading the data into Amazon S3 and then using the COPY command to load it into Redshift.

Keeping Your Data Up-To-Date

So, now what? You’ve built a script that pulls data from Salesforce and loads it into Redshift, but what happens tomorrow when you have piles of new data? Or a month from now when you add new custom fields and need to change your database structure to add them?

The key is to build your script in such a way that it can also identify incremental updates to your data. This is where functionality like the Salesforce streaming API can come in handy.

Other Data Warehouse Options

Redshift is totally awesome, but sometimes you need to start smaller or optimize for different things. In this case, many people choose to get started with Postgres, which is an open source RDBMS that uses nearly identical SQL syntax to Redshift. If you’re interested in seeing the relevant steps for loading this data into Postgres, check out Salesforce to Postgres

Easier and Faster Alternatives

If all this sounds a bit overwhelming, don’t be alarmed. If you have all the skills necessary to go through this process, chances are building and maintaining a script like this isn’t a very high-leverage use of your time.

Thankfully, products like Stitch were built to solve this problem automatically. With just a few clicks, Stitch starts extracting your Salesforce data via the API, structuring it in a way that is optimized for analysis, and inserting that data into your Amazon Redshift data warehouse.