Extracting data from Salesforce

December 6, 2015

(This article was first published on Adventures in Data, and kindly contributed to R-bloggers)

I have been asked to access and present some of our own internal data, stored on a CRM system called Salesforce. Luckily for me someone had already written a set of R bindings for it (phew). As always thank a million to the authors of RForcecom, details of which can be found here. A while ago, I was struggling to extract data from objects because you needed to know the names of the fields you wanted to return before submitting your query. Seems simple but this had me stumped for a while so I thought I would share the solution.

First we authenticate the session (I have all my keys in a seperate folder).

session <- rforcecom.login(username, password, instanceURL, apiVersion)

Now we can get a list of all the objects available to us.

objects <- rforcecom.getObjectList(session)

Here is the tricky bit, to query one of these objects we need to know the names of the fields we’re interested in. I just wanted everything so wrote a wrapper that would pull all of the fields.

getAllFields <- function(objectName) {
  description <- rforcecom.getObjectDescription(session, objectName)
  fields <- as.character(description$name)
  rforcecom.retrieve(session, objectName, fields)

Now we can call this function and we’re done.

accounts <- getAllFields("Account")

To leave a comment for the author, please follow the link and comment on their blog: Adventures in Data.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)