How to bulk delete Salesforce default datasets using RForcecom

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")

 

 

Advertisements

Data Science and Software Engineering

Posted in R

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: