Usage
sf_create_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 forsf_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 toTRUE
the URL, header, and body will be printed for each request, along with additional diagnostic information where available.
Examples
if (FALSE) { # \dontrun{
# read the metadata of the existing Account object
# we will use this object as a template to create a custom version
metadata_info <- sf_read_metadata(metadata_type='CustomObject',
object_names=c('Account'))
custom_metadata <- metadata_info[[1]]
# remove default actionOverrides, this cannot be set during creation
custom_metadata[which(names(custom_metadata) %in% c("actionOverrides"))] <- NULL
# remove fields since its a custom object and the standard ones no longer exist
custom_metadata[which(names(custom_metadata) %in% c("fields"))] <- NULL
# remove views so that we get the Standard List Views
custom_metadata[which(names(custom_metadata) %in% c("listViews"))] <- NULL
# remove links so that we get the Standard Web Links
custom_metadata[which(names(custom_metadata) %in% c("webLinks"))] <- NULL
# now make some adjustments to customize the object
this_label <- 'Custom_Account43'
custom_metadata$fullName <- paste0(this_label, '__c')
custom_metadata$label <- this_label
custom_metadata$pluralLabel <- paste0(this_label, 's')
custom_metadata$nameField <- list(displayFormat='AN-{0000}',
label='Account Number',
type='AutoNumber')
custom_metadata$fields <- list(fullName="Phone__c",
label="Phone",
type="Phone")
# set the deployment status, this must be set before creation
custom_metadata$deploymentStatus <- 'Deployed'
# make a description to identify this easily in the UI setup tab
custom_metadata$description <- 'created by the Metadata API'
new_custom_object <- sf_create_metadata(metadata_type = 'CustomObject',
metadata = custom_metadata,
verbose = TRUE)
# adding custom fields to our object
# input formatted as a list
custom_fields <- list(list(fullName='Custom_Account43__c.CustomField66__c',
label='CustomField66',
length=100,
type='Text'),
list(fullName='Custom_Account43__c.CustomField77__c',
label='CustomField77',
length=100,
type='Text'))
# formatted as a data.frame
custom_fields <- data.frame(fullName=c('Custom_Account43__c.CustomField88__c',
'Custom_Account43__c.CustomField99__c'),
label=c('Test Field1', 'Test Field2'),
length=c(44,45),
type=c('Text', 'Text'))
new_custom_fields <- sf_create_metadata(metadata_type = 'CustomField',
metadata = custom_fields)
} # }