sf_download_attachment: Download an Attachment

View source: R/attachments.R

sf_download_attachmentR Documentation

Download an Attachment

Description

[Stable]

This function will allow you to download an attachment to disk based on the attachment body, file name, and path.

Usage

sf_download_attachment(
  body,
  name = NULL,
  sf_id = NULL,
  object_name = c("Attachment", "Document"),
  path = "."
)

Arguments

body

character; a URL path to the body of the attachment in Salesforce, typically retrieved by sf_query on the Attachment object. Alternatively, you can specify the Salesforce Id of the Attachment.

name

character; the name of the file you would like to save the content to. Note that you should include the file extension in this name and if this argument is left NULL, then a query will be made to determine the name and file extension needed. This process may result in a slower download process, so attempt to provide the body and name arguments whenever possible for the best performance.

sf_id

character; a Salesforce generated Id that uniquely identifies a record.

object_name

character; the name of the Salesforce object that the function is operating against (e.g. "Account", "Contact", "CustomObject__c").

path

character; a directory path where to create file, defaults to the current directory.

Value

character; invisibly return the file path of the downloaded content

Salesforce Documentation

See Also

Other Attachment functions: check_and_encode_files(), sf_create_attachment(), sf_delete_attachment(), sf_update_attachment()

Examples

## Not run: 
# downloading all attachments for a Parent record
# if your attachment name doesn't include the extension, then you can use the 
# ContentType column to append it to the Name, if needed
queried_attachments <- sf_query("SELECT Id, Body, Name, ContentType 
                                 FROM Attachment 
                                 WHERE ParentId = '0016A0000035mJ5'")
mapply(sf_download_attachment, queried_attachments$Body, queried_attachments$Name)

# downloading an attachment by its Id
# (the file name will be the same as it exists in Salesforce)
sf_download_attachment(sf_id = queried_attachments$Id[1])

## End(Not run)

salesforcer documentation built on March 18, 2022, 6:26 p.m.