This function will allow you to create attachments (and other blob data, such as Documents) by supplying file paths (absolute or relative) to media that you would like to upload to Salesforce along with accompanying metadata, such as a Description, Keywords, ParentId, FolderId, etc.
Arguments
- attachment_input_data
named vector
,matrix
,data.frame
, ortbl_df
; data can be coerced into adata.frame
. The input must contain a column entitled 'Body' with an absolute or relative file path (unless creating a Document using a Url) along with other required fields depending on the object.If performing anupdate
operation, then one column or field of the input must be theId
of the record to modify.- object_name
character
; the name of the Salesforce object that the function is operating against (e.g. "Account", "Contact", "CustomObject__c").- api_type
character
; one of"REST"
,"SOAP"
,"Bulk 1.0"
, or"Bulk 2.0"
indicating which API to use when making the request.- control
list
; a list of parameters for controlling the behavior of the API call being used. For more information of what parameters are available look at the documentation forsf_control
.- ...
arguments passed to
sf_control
or further downstream tosf_bulk_operation
- verbose
logical
; an indicator of whether to print additional detail for each API call, which is useful for debugging. More specifically, when set toTRUE
the URL, header, and body will be printed for each request, along with additional diagnostic information where available.
Note
The length of any file name can’t exceed 512 bytes (per Bulk 1.0 API). The SOAP API create call restricts these files to a maximum size of 25 MB. For a file attached to a Solution, the limit is 1.5 MB. The maximum email attachment size is 3 MB. You can only create or update documents to a maximum size of 5 MB. The REST API allows you to insert or update blob data limited to 50 MB of text data or 37.5 MB of base64–encoded data.
See also
Other Attachment functions:
check_and_encode_files()
,
sf_delete_attachment()
,
sf_download_attachment()
,
sf_update_attachment()
Examples
if (FALSE) { # \dontrun{
# upload two PDFs from working directory to a particular record as Attachments
file_path1 <- here::here("doc1.pdf")
file_path2 <- here::here("doc2.pdf")
parent_record_id <- "0036A000002C6MmQAK"
attachment_details <- tibble(Body = c(file_path1, file_path2),
ParentId = rep(parent_record_id, 2))
result <- sf_create_attachment(attachment_details)
# the function supports inserting all blob content, just update the
# object_name argument to add the PDF as a Document instead of an Attachment
document_details <- tibble(Name = "doc1.pdf",
Description = "Test Document 1",
Body = file_path1,
FolderId = "00l6A000001EgIwQAK", # replace with your FolderId!
Keywords = "example,test,document")
result <- sf_create_attachment(document_details, object_name = "Document")
# the Bulk API can be invoked using api_type="Bulk 1.0" which will automatically
# take a data.frame of Attachment info and create a ZIP file with CSV manifest
# that is required for that API
result <- sf_create_attachment(attachment_details, api_type="Bulk 1.0")
} # }