Explore Courses Blog Tutorials Interview Questions
0 votes
in Salesforce by (11.9k points)

My final aim is to extract data from Salesforce accounts for general use in R. I spotted the RForcecom package ( which looks very useful indeed, thanks @hiratake55 for writing it! Unfortunately, I am having a small problem.

I am able to sign in to my account and then access objects within and store as a data.frame just as the intro notes say.

The problem is that I want to access certain fields within the SOQL object and I don't know the names of those fields.

Here is what I have so far:


    username <- "" # my email address

    password <- "" # my website password + security token

    instanceURL <- ""

    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 a data.frame just as RForcecom says on the tin. Now I also want to extract for example the field "Contact Owner Alias" (the field has this name on the web interface of SalesForce). 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


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


I know that part of the problem is my unfamiliarity with SOQL but it thought I would ask around to see if this had been solved inside R. If the answer is "go learn SOQL" that's ok, I just thought I would ask first.

Thanks for any help!

1 Answer

0 votes
by (32.1k points)
edited by

You will need to use Salesforce API name of the fields along with  retrieve() and SOQL query() function call.

With a custom field like "Contact Owner Alias" you might be looking for an API name like "ContactOwnerAlias__c". Note the __c suffix indicates that it is a custom field rather than a standard field.

You can get the API name by scrutinizing the field in the Salesforce UI, or, as you noticed, using an external tool like workbench to find it in the field metadata.

To learn in-depth about Salesforce, sign up for an industry-based Salesforce Certification!

Browse Categories