sf_upsert_metadata {salesforcer} | R Documentation |
Upsert Object or Field Metadata in Salesforce
Description
This function takes a list of Metadata components and sends them to Salesforce for creation or update if the object already exists
Usage
sf_upsert_metadata(
metadata_type,
metadata,
control = list(...),
...,
all_or_none = deprecated(),
verbose = FALSE
)
Arguments
metadata_type |
|
metadata |
|
control |
|
... |
arguments passed to |
all_or_none |
|
verbose |
|
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.
See Also
Examples
## Not run:
# 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)
## End(Not run)