deleteMetadata()
Syntax
DeleteResult[] = metadataConnection.delete(string metadataType, string[] fullNames);
Usage
Use the deleteMetadata() call to delete 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 the AllOrNoneHeader isn’t used in any API version, this call can delete a partial set of records for records with no errors (equivalent to AllOrNoneHeader=false). If AllOrNoneHeader is set to true, no records are deleted if one or more records cause a failure.
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.
Rules and Guidelines
When deleting components, consider the following rules and guidelines:
- Your client application must be logged in with sufficient access rights to delete individual components within the specified component. For more information, see Factors that Affect Data Access in the Salesforce Object Reference.
- In addition, sometimes you also need permission to access this component’s parent component.
- To ensure referential integrity, this call supports cascading deletions. If you delete a parent component, you delete its children automatically, as long as each child component can be deleted.
Basic Steps for Deleting Metadata Components
Use the following process to delete metadata components:
- Determine the metadata type of the components you want to delete and the fullName of each component to delete. You can delete only components of the same type in a single call. The full names must match one or more full names returned by the listMetadata() call, which includes namespace prefixes. If you obtain the fullName from a package manifest file, and the component has a namespace prefix, prepend the namespace prefix to the fullName. Use this syntax: namespacePrefix__ComponentName. For example, for the custom object component MyCustomObject__c and the namespace MyNS, the fullName is MyNS__MyCustomObject__c. See Metadata for more details on the fullName field.
- Invoke the deleteMetadata() call. For the
first argument, pass in the name of the metadata type. For the second argument,
pass in an array of full names corresponding to the components you wish to
delete.
A DeleteResult object is returned for each component you try to delete. It contains information about whether the operation was successful, the name of the deleted component, and any errors returned if the operation wasn’t successful.
Sample Code—Java
public void deleteCustomObjectSync() {
try {
DeleteResult[] results = metadataConnection.deleteMetadata(
"CustomObject", new String[] { "MyCustomObject1__c",
"MyCustomObject2__c" });
for (DeleteResult r : results) {
if (r.isSuccess()) {
System.out.println("Deleted component: " + r.getFullName());
} else {
System.out
.println("Errors were encountered while deleting "
+ 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 |
---|---|---|
metadataType | string | The metadata type of the components to delete. |
fullNames | string[] | Array of full names of the components to delete. Limit: 10. (For CustomMetadata and CustomApplication only, the limit is 200.) 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. |