sf_create_attachment: Create Attachments

View source: R/attachments.R

sf_create_attachmentR Documentation

Create Attachments

Description

[Experimental]

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.

Usage

sf_create_attachment(
  attachment_input_data,
  object_name = c("Attachment", "Document"),
  api_type = c("SOAP", "REST", "Bulk 1.0", "Bulk 2.0"),
  control = list(...),
  ...,
  verbose = FALSE
)

Arguments

attachment_input_data

named vector, matrix, data.frame, or tbl_df; data can be coerced into a data.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 an update operation, then one column or field of the input must be the Id 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 for sf_control.

...

arguments passed to sf_control or further downstream to sf_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 to TRUE the URL, header, and body will be printed for each request, along with additional diagnostic information where available.

Value

tbl_df with details of the created records

Salesforce Documentation

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

## Not run: 
# 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")

## End(Not run)

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