Dream to Learn is shutting down...

We are very sorry to say that Dream to Learn will be shutting down as of December 28th, 2019. If you have content that you wish to keep, you should make a copy of it before that date.


An Idiot's Guide to Integrating SALESFORCE with R - Part 1 - Survey Tools

Recommended By

  • Ryan Anderson
POSTED IN: Data Analytics & Visualization Blog


This is a blog entry of my exploratory journey into how I might integrate R into SalesForce.   I'm not clear about my destination, but you are very welcome to tag along for the ride.   A warning - my methods are a bit unorthodox - and given most of my 'coding' capabilities arise from R - I sometimes take the long way around.  

However, if you are an R NewBie, or just curious about one method to plug R into SalesForce, I hope you'll find some of the information below useful! 


SalesForce is best known for its customer relationship management (CRM) cloud based software - and is rapidly expanding into more commercial applications.  Judging by the downtown SFO construction I pass every day - a massive project erecting their new global HQ - and their once a year, gravity bending "DreamForce" (also in SFO) - they are doing quite well.     Oh - and there is the 40 billion dollar market cap :) 

My brother in law was just visiting - we got into a conversation about SalesForce & Sugar CRM  http://www.sugarcrm.com/  He mentioned that a couple of folks he worked with were very impressed with the Developer tools that SF offered.  Very accessible, open, and versatile. This got me thinking about having a poke at SF - especially if the DEVELOPER'S PLATFORM was half as good as it sounded.  I wondered if SF might be a nice 'front end' for the R analytics I've been monkeying around with.

So here we are!  Not sure what's going to pop out the other end - but am going to start with a survey of other articles and tools that are already out there. 

Step 1- Sign up for SalesForce Developers Platform 

  • https://developer.salesforce.com/trailhead
  • This was super easy to do - low friction sign-up.
  • Doesn't look like SF want any money or credit cards.
  • Heaps of 'demos' and tutorials - I poked at a couple (will come back to them) - I dont normally read the instructions - but looks like given the complexity of things - might be taking tutorials and reading the manual this time :)
    • Getting Started with the Force.com Platform Learn fundamentals such as mapping your data model, managing data, & customizing the UI. 

    • Intro to Visual App Development Practice automating workflows & approvals, building reports & dashboards, setting up Chatter, & deploying your apps.

    • Intro to Programmatic App Development Experiment with Apex, a Java-like language, & Visualforce, similar to HTML. Then dive into integration & lifecycle management.

  • It looks like the folks at SalesForce are trying to make this easy.

Step 2 - Prior Articles - who has already 'broken trail'?

Long ago - I used to snowboard in the back-country of the rockies.  Hiking up mountains in waist deep snow to find some lovely fluffy powder lines.   The folks that break trail ahead can really make the climb easier.

Below are some URLs - going to (1) search out a dozen of the best candidates (2) do a quick scan to look at the talent and paths that have been blazed and (3) work through a few in coming weeks.  Will come back and edit to 'rate' them for you.

Prior Articles on SF <-> R Integration Article / URLAuthorComments

RForcecom – An R package 




So far this is EXCELLENT

Step 3 - R <- Install.Packages ("for_salesforce")

You just know there are some juicy R packages that are going to make life easier.  Here are a few.

install.packages("RForcecom")   #(this one does quite a bit)


Step 4 - CONNECT - Have your first "hero moment" :) 

Getting a basic connection from SF to R was FAR easier than I expected - the Hiramura blog/instructions (above) were excellent.  

ON GETTING YOUR TOKEN - SUPPLEMENTAL NOTE #1 >  there are two URLs that you touch: (1) the Dev/Trailhead URL; and  (2) https://na24.salesforce.com etc.. - this second one is "DEV" where you get your security token from > "To get or reset your security token: (I reset mine) At the top of any Salesforce page, click the down arrow next to your name. From the menu under your name, select Setup or My Settings—whichever one appears. From the left pane, select one of the following: If you clicked Setup, select My Personal Information | Reset My Security Token. If you clicked My Settings, select Personal | Reset My Security Token. https://help.salesforce.com/apex/HTViewHelpDoc?id=user_security_token.htm



the dev environment has dummy data it returns (e.g. GenePoint)



######### Idiot's Guide to Integrating SalesForce & R

#  First section guided by instructions here: https://hiratake55.wordpress.com/2013/03/28/rforcecom/
#  They are VERY good (at least up to section 4)

#  this installed OK for me on 4/26/2015 R 3.1.2 running on a PC Win 7
#  yep

## OK - let's log in - from the package documentation 
username <- "ryan[@t]dreamtolearn[d0t]com" # normal email/sflogin you will need your own :-)
# you will need your own :-)
instanceURL <- "https://na24.salesforce.com/"
apiVersion <- "27.0"  ## left this default - did not check
session <- rforcecom.login(username, password, instanceURL, apiVersion)

objectName <- "Account"
fields <- c("Id", "Name", "Phone")
rforcecom.retrieve(session, objectName, fields)
## who hoo! Got their dummy data back - mini-hero-moment
#Id                                Name           Phone
#1  0011a000003P3OtAAK                           GenePoint  (650) 867-3450
#2  0011a000003P3OuAAK                United Oil & Gas, UK +44 191 4956203
#3  0011a000003P3OvAAK         United Oil & Gas, Singapore  (650) 450-8810

Interested in more content by this author?

About the Author

Ryan Anderson

Ryan Anderson

Hi! I like to play with data, analytics and hack around with robots and gadgets in my garage. Lately I've been learning about machine learning.

About this blog

Description is...<br/>Data Analytics & Visualization Blog - Generating insights from Data since 2013

Created: July 25, 2014


Up Next