updateMetadata()
Syntax
SaveResult[] = metadataConnection.updateMetadata(Metadata[] metadata);
Usage
Use the updateMetadata() call to update any component that extends Metadata. All components must be of the same type in the same call. For more details, see Metadata Components and Types.
This call executes synchronously, which means that the call returns only when the operation completes.
Starting in API version 34.0, this call supports the AllOrNoneHeader header. By default, if AllOrNoneHeader isn’t used in API version 34.0 and later, this call can save a partial set of records for records with no errors (equivalent to AllOrNoneHeader=false). In API version 33.0 and earlier, the default behavior is to only save all records when there are no failures in any record in the call (equivalent to AllOrNoneHeader=true).
Version
Available in API version 30.0 and later.
Permissions
Your client application must be logged in with the Modify Metadata Through Metadata API Functions or Modify All Data permission.
Required Fields
You must supply values for all the required fields in the component.
Valid Field Values
You must supply values that are valid for the field’s data type, such as integers for integer fields (not alphabetic characters). In your client application, follow the data formatting rules specified for your programming language and development tool. (Your development tool handles the appropriate mapping of data types in SOAP messages.)
String Values
When storing values in string fields, the API trims any leading and trailing white space. For example, if the value of a label field is entered as "MyObject ", the value is stored in the database as "MyObject".
Basic Steps for Updating Metadata Components
Use this process to update metadata components.
- Create an array of the components you want to update. All components must be of the same type.
- Invoke the updateMetadata() call, passing
in the array of metadata components to update.
A SaveResult object is returned for each component you try to update. It contains information about whether the operation was successful, the name of the component updated, and any errors returned if the operation wasn’t successful.
Sample Code—Java
public void updateCustomObjectSync() {
try {
CustomObject co = new CustomObject();
String name = "MyCustomObject1";
co.setFullName(name + "__c");
co.setDeploymentStatus(DeploymentStatus.Deployed);
co.setDescription("Updated description");
co.setLabel(name + " Object Update");
co.setPluralLabel(co.getLabel() + "s");
co.setSharingModel(SharingModel.ReadWrite);
// Name field with a type and label is required
CustomField cf = new CustomField();
cf.setType(FieldType.Text);
cf.setLabel(co.getFullName() + " Name");
co.setNameField(cf);
SaveResult[] results = metadataConnection
.updateMetadata(new Metadata[] { co });
for (SaveResult r : results) {
if (r.isSuccess()) {
System.out.println("Updated component: " + r.getFullName());
} else {
System.out
.println("Errors were encountered while updating "
+ r.getFullName());
for (Error e : r.getErrors()) {
System.out.println("Error message: " + e.getMessage());
System.out.println("Status code: " + e.getStatusCode());
}
}
}
} catch (ConnectionException ce) {
ce.printStackTrace();
}
}
Arguments
Name | Type | Description |
---|---|---|
metadata | Metadata[] | Array of one or more metadata components you wish to update.
Limit: 10. (For CustomMetadata and CustomApplication only, the limit is 200.) You must submit arrays of only one type of component. For example, you can submit an array of 10 custom objects or 10 profiles, but not a mix of both types. |