This article describes how to import data from Salesforce into Displayr.
- A Displayr document.
- A Salesforce account with valid user credentials and a security token from Profile icon > Settings > Reset My Security Token.
1. Select Data Sets > Plus (+) > R.
2. Enter a name for the data set under Name.
3. Paste the below R code where it states "Enter your R code here":
# Get authentication details
username <- 'yourusername'
userpw <- 'yourpassword'
token <- 'yoursecuritytoken'
password.token <- paste(userpw,token,sep="")
# Run query
session <- rforcecom.login(username, password.token)
# Execute a SOQL
query <- "SELECT account.ID, account.Name FROM Account"
accounts <- rforcecom.query(session, query)
- Note, you will need to replace your username, password and security token with the appropriate user credentials.
- This query uses the RForcecom R package which logs into Salesforce using your credentials and then executes your query. In this example, we are calling the account ids and names.
- Salesforce utilizes a variation of standard SQL called Salesforce Object Query Language (SOQL). See the Salesforce SOQL Documentation library for details on how to structure SOQL syntax.
3. OPTIONAL: If you wish to make this call take place daily, you can add the below lines to the top of your R code:
UpdateEvery(1, "days", options = "wakeup")
4. OPTIONAL: You can test the R code first via Calculation > Custom Code until you have it working as this method allows for troubleshooting.