Closed sckaiser closed 8 years ago
@sckaiser You can currently do this via the Bulk API operations. The rforcecom.update()
function is a little more fickle since it uses the SOAP API. For that API I found an example of how to format the XML for such an update at this link: https://developer.salesforce.com/page/PartnerUpdate. It might take awhile to get it into the framework that rforcecom.update()
uses, so I will provide the code in another message to show how to directly send the XML over to the SOAP API if you insist on using it.
@sckaiser Example Update to Null using the Bulk API:
session <- rforcecom.login(user, password)
job_info <- rforcecom.createBulkJob(session, operation='update', object='Account')
update_data <- data.frame(Id='0016999999999', CustomField__c=NA)
batches_info <- rforcecom.createBulkBatch(session,
jobId=job_info$id,
data=update_data)
# 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)
@sckaiser Example Update to Null using the SOAP API:
Remember to change to your specific Id in the root
variable shown below
root <-
'<update>
<sobject xsi:type="sf:Account">
<id>0016999999999</id>
<fieldsToNull>CustomField__c</fieldsToNull>
</sobject>
</update>'
#build soapBody
soapBody <- paste0('<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<env:Header>
<SessionHeader>
<sessionId>', session['sessionID'], '</sessionId>
</SessionHeader>
</env:Header>
<env:Body>',
as(root, 'character'),
'</env:Body>
</env:Envelope>')
# perform request
h <- basicHeaderGatherer()
t <- basicTextGatherer()
httpHeader <- c("SOAPAction"='update', 'Content-Type'="text/xml")
curlPerform(url=URL, postfields=soapBody,
httpheader=httpHeader, customrequest="PATCH",
headerfunction = h$update, writefunction = t$update,
ssl.verifypeer=F)
x.root <- xmlRoot(xmlInternalTreeParse(t$value(), asText=T))
x.root
will return a blank if successful
@ReportMort Thanks Steve! I'll mark as closed.
I have fields which I need to delete back to an 'empty' value. In the SFDC GUI, this can be done by clicking on the field and hitting backspace. I've tried a couple of commands to programmatically achieve the same effect, but all return errors:
rforcecom.update(session, "Account", <redacted>, c(CustomField__c = ""))
rforcecom.update(session, "Account", <redacted>, c(CustomField__c = " "))
rforcecom.update(session, "Account", <redacted>, c(CustomField__c = NA))
All return: Error in rforcecom.update(session, "Account",, c(CustomField__c = "")) :
XML_PARSER_ERROR: '' (or " " or 'NA') is not valid for the type xsd:double