Salesforce to BigQuery

This page provides you with instructions on how to extract data from Salesforce and load it into Google BigQuery. (If this manual process sounds onerous, check out Stitch, which can do all the heavy lifting for you in just a few clicks.)

What is Salesforce?

Salesforce is the CRM to rule them all. It's part of the Force.com cloud platform which encompasses a huge variety offerings not limited to just CRM. The Salesforce CRM is amazingly customizable, has tons of integration functionality, and includes almost too many bells and whistles to count. Companies can do everything from managing account planning to time management and team collaboration.

What is Google BigQuery?

Google BigQuery is a data warehouse that delivers super-fast results from SQL queries, which it accomplishes using a powerful engine dubbed Dremel. With BigQuery, there's no spinning up (and down) clusters of machines as you work with your data. With all of that said, it's clear why some claim that BigQuery prioritizes querying over administration. It's super fast, and that's the reason why most folks use it.

Getting data out of Salesforce

Step one is to get all of that precious data out of Salesforce. For our purposes here, we'll focus on CRM and customer datasets. There are a great many Salesforce API's available for their various products. There is a list on one of their helpdesk posts with some direction on when and how to use each API.

By looking through that post, you can get an idea of which API makes the most sense for your use case. For this post, we'll discuss the REST API and show some examples. Keep in mind that the same data is available using other protocols (including streaming for real-time receipt of data).

SOQL (Salesforce Object Query Language) is what you will need to write for this project. Using SOQL, you'll have access to records such as accounts, leads, tasks, and many more.

Sample Salesforce data

The Salesforce Rest API can return JSON or XML formatted data depending on your preference. Here is what a sample response might look like in JSON format:

{
    "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"
        }, 

        ...

    ]
}

Loading data into Google BigQuery

Google Cloud Platform offers a helpful guide for loading data into BigQuery. You can use the bq command-line tool to upload the files to your awaiting datasets, adding the correct schema and data type information along the way. The bq load command is your friend here. You can find the syntax in the bq command-line tool quickstart guide. Iterate through this process as many times as it takes to load all of your tables into BigQuery.

Keeping Salesforce data up to date

So now what? You have a script that pulls data from Salesforce and loads it into a data warehouse. It's time to plan for 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 identify incremental updates to your data. This is where functionality like the Salesforce streaming API can come in handy.

Other data warehouse options

BigQuery is really great, but sometimes you need to optimize for different things when you're choosing a data warehouse. Some folks choose to go with Postgres or Redshift, which are two RDBMSes that use similar SQL syntax. If you're interested in seeing the relevant steps for loading this data into Postgres or Redshift, check out To Redshift and 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 Google BigQuery data warehouse.