📅 The Data Stack Show Live: The Future of Streaming Data

Register Now
By Rudderstack Team

How to Load data from Salesforce to Snowflake Step-by-Step

This post helps you with loading your data from Salesforce to Snowflake. This article considers you are going to use custom Snowflake ETL scripts to move your data from Salesforce and then model it accordingly. If you are looking to get analytics-ready data into Snowflake immediately, without the manual hassle, you can use an official Snowflake cloud-based ETL partner like RudderStack, so you can focus on what matters, getting value out of your data.

Extract data from Salesforce

You can’t use a Data Warehouse without data, so the first and most important step is to extract the data you want from Salesforce.

Salesforce has many products, and it’s also a pioneer in cloud computing and the API economy. This means that it offers a plethora of APIs to access the services and the underlying data. In this post, we’ll focus only on Salesforce CRM, which again exposes a large number of APIs.

People that write their own scripts to ETL cloud data from their data source can benefit from this excellent post from Salesforce’s Helpdesk about which API to use.

You will have the following options:

  • REST_API
  • SOAP API
  • Chatter REST_API
  • Bulk API
  • Metadata API
  • Streaming API
  • Apex REST_API
  • Apex SOAP API
  • Tooling API

Pull data from the Salesforce REST API

From the above list, the complexity and feature richness of the Salesforce API is more than evident. The REST API and the SOAP API are exposing the same functionalities but using different protocols. Interacting with the REST_API can be done using tools like CURL or Postman or using HTTP clients for your favorite language or framework. A few suggestions:

  • Apache HttpClient for Java
  • Spray-client for Scala
  • Hyper for Rust
  • Ruby rest-client
  • Python http-client

The Salesforce REST API supports OAuth 2.0 authentication. More information can be found in the Understanding Authentication article. After you successfully authenticate with the REST_API, you have to start interacting with its resources and start fetching data from it to load them on a warehouse.

It’s easy to get a list of all the resources we have access to. For example, using curl, we can execute the following:

curl https://na1.salesforce.com/services/data/v26.0/ -H "Authorization: Bearer token"

A typical response from the server will be a list of available resources in JSON or XML, depending on what you have asked as part of your request.

{
"sobjects" : "/services/data/v26.0/sobjects",
"licensing" : "/services/data/v26.0/licensing",
"connect" : "/services/data/v26.0/connect",
"search" : "/services/data/v26.0/search",
"query" : "/services/data/v26.0/query",
"tooling" : "/services/data/v26.0/tooling",
"chatter" : "/services/data/v26.0/chatter",
"recent" : "/services/data/v26.0/recent"
}

The Salesforce REST_API is very expressive. It also supports a language called Salesforce Object Query Language (SOQL) for executing arbitrarily complex queries. For example, the following curl command will return the name fields of accounts:

curl https://na1.salesforce.com/services/data/v20.0/query/?q=SELECT+name+from+Account -H "Authorization: Bearer token"

and the result will look like the following:

{
"done" : true,
"totalSize" : 14,
"records" :
[
{
"attributes" :
{

Again, the result can be either in JSON or XML serialization. We would recommend using JSON to make the whole data connection process easier because the most popular data warehousing solutions natively support it.

With XML, you might have to transform it first into JSON before loading any data to the repository. More information about SOQL can be found on the Salesforce Object Query Language specification page.

If for any reason you would prefer to use SOAP, then you should create a SOAP client first: for example, you can use the force.com Web Service Connector (WSC) client. Or create your own using the WSDL using the information provided by this guide.

Despite the protocol changes, the architecture of the API remains the same, so again you will be able to access the same resources.

After you have your client ready and you can connect to Salesforce, you ought to perform the following steps:

  • decide which resources to extract from the API
  • map these resources to the schema of the warehouse of the data repository that you will use
  • transform data into it and
  • load the transformed data on the repository based on the instructions below

As you can see, accessing the API alone is not enough for ensuring the operation of a pipeline that will safely and on time deliver data you own on a data warehousing solution for analysis.

Pull Data using the Salesforce Streaming API

Another interesting way of interacting with Salesforce is through the Streaming API.

With it, you define queries, and every time something changes to the data that register to this query you get notifications. So, for example, every time you get a new account created, the API will push a notification about the event to your desired service. This is an extremely powerful mechanism that can guarantee almost real-time updates on a Data Warehouse repository.

To implement something like that, though, you must consider the limitations of both ends while ensuring the delivery semantics that your use case requires for every data management infrastructure that you will build.

For more information, you can read the documentation of t