Description Details Author(s) References See Also Examples
Data Integration Feature for Force.com and Salesforce.com
Package: | RForcecom |
Type: | Package |
Version: | 1.1 |
Date: | 2016-07-01 |
License: | Apache License 2.0 |
LazyLoad: | yes |
Takekatsu Hiramura <thira@plavox.info>
Force.com REST API Developer's Guide
https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/
Web Services API Developer's Guide
https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/
Bulk API Developer's Guide
https://developer.salesforce.com/docs/atlas.en-us.api_asynch.meta/api_asynch/
XML httr plyr
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | ## Not run:
# Sign in to the Force.com
username <- "yourname@yourcompany.com"
password <- "YourPasswordSECURITY_TOKEN"
session <- rforcecom.login(username, password)
# Execute a SOQL
soqlQuery <- "SELECT Id, Name, Industry, AnnualRevenue FROM Account"
rforcecom.query(session, soqlQuery)
# Execute a SOSL
queryString <- "United"
rforcecom.search(session, queryString)
# Create a record
objectName <- "Account"
fields <- c(Name="R Analytics Service Ltd", Phone="5555-5555-5555")
rforcecom.create(session, objectName, fields)
# Retrieve record
objectName <- "Account"
fields <- c("name", "Industry", "AnnualRevenue")
rforcecom.retrieve(session, objectName, fields)
# Update a record
objectName <- "Account"
id <- "999x000000xxxxxZZZ"
fields <- c(Phone="9999-9999-9999")
rforcecom.update(session, objectName, id, fields)
# Upsert a record
objectName <- "Account";
externalIdField <- "AccountMaster__c"
externalId <- "AM-00000151"
fields <- c(Name="ABC Network Company", Phone="3333-3333-3333")
rforcecom.upsert(session, objectName, externalIdField, externalId, fields)
# Delete a record
objectName <- "Account";
id <- "999x000000xxxxxZZZ"
rforcecom.delete(session, objectName, id)
# Retrieve a server timestamp
rforcecom.getServerTimestamp(session)
# Logout
rforcecom.logout(session)
####
# Using the Bulk API
####
# Sign in to the Force.com
username <- "yourname@yourcompany.com"
password <- "YourPasswordSECURITY_TOKEN"
instanceURL <- "https://xxx.salesforce.com/"
apiVersion <- "34.0"
session <- rforcecom.login(username, password, instanceURL, apiVersion)
## BULK INSERT
# create a sample data.frame of 1000 records
n <- 1000
data <- data.frame(Name=paste('New Record:', 1:n),
stringsAsFactors=FALSE)
# run an insert job into the Account object
job_info <- rforcecom.createBulkJob(session,
operation='insert',
object='Account')
# split into batch sizes of 500 (2 batches for our 1000 row sample dataset)
batches_info <- rforcecom.createBulkBatch(session,
jobId=job_info$id,
data,
multiBatch = TRUE,
batchSize=500)
# check on status of each batch
batches_status <- lapply(batches_info,
FUN=function(x){
rforcecom.checkBatchStatus(session,
jobId=x$jobId,
batchId=x$id)
})
# get details on each batch
batches_detail <- lapply(batches_info,
FUN=function(x){
rforcecom.getBatchDetails(session,
jobId=x$jobId,
batchId=x$id)
})
# close the job
close_job_info <- rforcecom.closeBulkJob(session, jobId=job_info$id)
## BULK DELETE THE PRIOR INSERT
# format the data
batch_details_together <- plyr::ldply(batches_detail)
delete_ids <- data.frame(id=batch_details_together[,"Id"],
stringsAsFactors=FALSE)
job_info <- rforcecom.createBulkJob(session, operation='delete', object='Account')
batches_info <- rforcecom.createBulkBatch(session,
jobId=job_info$id,
data=delete_ids)
# check on status of each batch
batches_status <- lapply(batches_info,
FUN=function(x){
rforcecom.checkBatchStatus(session,
jobId=x$jobId,
batchId=x$id)
})
# get details on each batch
batches_detail <- lapply(batches_info,
FUN=function(x){
rforcecom.getBatchDetails(session,
jobId=x$jobId,
batchId=x$id)
})
# close the job
close_job_info <- rforcecom.closeBulkJob(session, jobId=job_info$id)
## BULK QUERY
query <- "SELECT Id, Name FROM Account LIMIT 10"
job_info <- rforcecom.createBulkJob(session, operation='query', object='Account')
batch_query_info <- rforcecom.submitBulkQuery(session,
jobId=job_info$id,
query=query)
batch_query_status <- rforcecom.checkBatchStatus(session,
jobId=batch_query_info$jobId,
batchId=batch_query_info$id)
batch_query_details <- rforcecom.getBatchDetails(session,
jobId=batch_query_info$jobId,
batchId=batch_query_info$id)
batch_query_recordset <- rforcecom.getBulkQueryResult(session,
jobId=batch_query_info$jobId,
batchId=batch_query_info$id,
resultId=batch_query_details$result)
close_job_info <- rforcecom.closeBulkJob(session, jobId=job_info$id)
## BULK INSERT ATTACHMENTS
# prepare your .zip file and request.txt manifest before calling these functions
file <- 'request.zip'
job_info <- rforcecom.createBulkJob(session, operation='insert', object='Attachment')
batch_attachment_info <- rforcecom.insertBulkAttachments(session,
jobId=job_info$id,
file=file)
batch_attachment_status <- rforcecom.checkBatchStatus(session,
jobId=batch_attachment_info$jobId,
batchId=batch_attachment_info$id)
batch_attachment_details <- rforcecom.getBatchDetails(session,
jobId=batch_attachment_info$jobId,
batchId=batch_attachment_info$id)
# close the job
close_job_info <- rforcecom.closeBulkJob(session, jobId=job_info$id)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.