RForcecom, access to unknown field names

My ultimate goal is to extract data from Salesforce accounts for general use in R. I noticed the RForcecom package ( https://hiratake55.wordpress.com/2013/03/28/rforcecom/ ), which looks very useful, thanks @ hiratake55 for it letter! Unfortunately, I have a little problem.

I can log in to my account and then access the objects inside and save as data.frame just like insert notes say.

The problem is that I want to access certain fields in a SOQL object, and I do not know the names of these fields.

Here is what I still have:

  library(RForcecom) username <- "" # my email address password <- "" # my website password + security token instanceURL <- "https://eu5.salesforce.com/" apiVersion <- "34.0" session <- rforcecom.login(username, password, instanceURL, apiVersion) # R Query objectName <- "Contact" fields <- c("Id", "Name", "Phone") rforcecom.retrieve(session, objectName, fields) 

This works fine and returns data.frame just like RForcecom says tin. Now I also want to extract, for example, the "Contact Owner Alias" field (the field has this name in the SalesForce web interface). I tried the following:

  fields <- c("Id", "Name", "Phone", "Contact Owner Alias") rforcecom.retrieve(session, objectName, fields) 

This gave an error:

  Error in rforcecom.query(session, soqlQuery) : MALFORMED_QUERY: Id, Name, Phone, Contact Owner Alias FROM Contact ^ ERROR at Row:1:Column:38 unexpected token: Alias 

Question

Is there a way to get all the file names in R? Or is there a way to return data from all fields without knowing their names.

CAVEAT

I know that part of the problem is my unfamiliarity with SOQL, but she thought that I would ask to find out if it was allowed inside R. If the answer is β€œgo learn SOQL”, this is normal, I just thought I would ask first.

Thanks for any help!

+5
source share
3 answers

When calling the retrieve() and and SOQL query() functions, you will need to use the Salesforce API name for the corresponding fields.

With a custom field such as "Contact Alias", you will most likely be looking for an API name, such as "ContactOwnerAlias__c". Note the __c suffix, which indicates that this is a custom field, not a standard field.

You can get the API name by checking the field in the Salesforce user interface or, as you have found, using an external tool like workbench to find it in the field metadata.

I do not know R, but found that there is a rforcecom.getObjectDescription () method in the RForcecom presentation in UseR! 2014 . This will probably return the field metadata for an object that you could use to get the API field name.

+4
source

Sorry for the delay and thanks Daniel B. To update, I solved this with your suggestion as follows

 # grab SForce Data library(RForcecom) # session login etc username <- "Nope" password <- "Nope" instanceURL <- "https://eu5.salesforce.com/" apiVersion <- "34.0" session <- rforcecom.login(username, password, instanceURL, apiVersion) # query objects <- rforcecom.getObjectList(session) # pull all fields of an object getAllFields <- function(objectName) { description <- rforcecom.getObjectDescription(session, objectName) fields <- as.character(description$name) rforcecom.retrieve(session, objectName, fields) } # grab the data accounts <- getAllFields("Account") 
+5
source
 library(gsubfn) # this is used for fn$indentity account.nm <- rforcecom.getObjectDescription(session, "Account") nm <- toString( sprintf("%s", account.nm$name)) account.query <- fn$identity( "SELECT $nm FROM Account") Account <- rforcecom.query(session, account.query) 
0
source

Source: https://habr.com/ru/post/1232179/


All Articles