[Experimental]

This function takes a list of Metadata components and sends them to Salesforce for creation or update if the object already exists

sf_upsert_metadata(
  metadata_type,
  metadata,
  control = list(...),
  ...,
  all_or_none = deprecated(),
  verbose = FALSE
)

Arguments

metadata_type

character; string on what type of metadata to create.

metadata

list; metadata components to be created formatted as XML before being sent via API.

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

all_or_none

logical; allows a call to roll back all changes unless all records are processed successfully.

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

A tbl_df containing the creation result for each submitted metadata component

Note

The upsert key is based on the fullName parameter of the metadata, so updates are triggered when an existing Salesforce element matches the metadata type and fullName.

Examples

if (FALSE) {
# create an object that we can confirm the update portion of the upsert
base_obj_name <- "Custom_Account1"
custom_object <- list()
custom_object$fullName <- paste0(base_obj_name, "__c")
custom_object$label <- paste0(gsub("_", " ", base_obj_name))
custom_object$pluralLabel <- paste0(base_obj_name, "s")
custom_object$nameField <- list(displayFormat = 'AN-{0000}', 
                                label = paste0(base_obj_name, ' Number'), 
                                type = 'AutoNumber')
custom_object$deploymentStatus <- 'Deployed'
custom_object$sharingModel <- 'ReadWrite'
custom_object$enableActivities <- 'true'
custom_object$description <- paste0(base_obj_name, " created by the Metadata API")
custom_object_result <- sf_create_metadata(metadata_type = 'CustomObject',
                                           metadata = custom_object)
# now update the object that was created
upsert_metadata <- list(custom_object, custom_object)
upsert_metadata[[1]]$fullName <- 'Custom_Account1__c'
upsert_metadata[[1]]$label <- 'New Label Custom_Account1'
upsert_metadata[[1]]$pluralLabel <- 'Custom_Account1s_new'
upsert_metadata[[2]]$fullName <- 'Custom_Account2__c'
upsert_metadata[[2]]$label <- 'New Label Custom_Account2'
upsert_metadata[[2]]$pluralLabel <- 'Custom_Account2s_new'
upserted_custom_object_result <- sf_upsert_metadata(metadata_type = 'CustomObject',
                                                    metadata = upsert_metadata)
}