How to bulk delete Salesforce default datasets using RForcecom

[This article was first published on R – Data science & Software development, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

When you signed up a brand new Salesforce account, you can see lots of dummy dataset (such as Acme Inc.). If you are a Salesforce developer or administrator, you might have to delete all records prior to release the account to Salesforce users (And it is really painful job).

In this case, you can do delete such records at one time by using RForcecom.

Here is a very simple code (just 20 lines) to perform.

library("RForcecom")

username<-""
password<-""
token<-""

session<-rforcecom.login(username, paste0(password,token))

deleteAll<-function(objectName){
  df<-rforcecom.retrieve(session, objectName, c("Id"))
  deleteRecords <- function(id){
    x<-as.character(id)
    rforcecom.delete(session, objectName, id)
  }
  lapply(df$Id, deleteRecords)
}
deleteAll("Contact")
deleteAll("Opportunity")
deleteAll("Lead")
deleteAll("Account")
deleteAll("Campaign")
deleteAll("ContentDocument")

 

 

To leave a comment for the author, please follow the link and comment on their blog: R – Data science & Software development.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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)