Newer Version Available

This content describes an older version of this product. View Latest

deleteMetadata()

Deletes one or more metadata components from your organization synchronously.

Syntax

1DeleteResult[] = 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 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 SOAP API Developer Guide.
  • In addition, you might 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:

  1. 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. See Metadata for more details on the fullName field.
  2. 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

1public void deleteCustomObjectSync() {
2    try {
3        DeleteResult[] results = metadataConnection.deleteMetadata(
4                "CustomObject", new String[] { "MyCustomObject1__c",
5                        "MyCustomObject2__c" });
6        for (DeleteResult r : results) {
7            if (r.isSuccess()) {
8                System.out.println("Deleted component: " + r.getFullName());
9            } else {
10                System.out
11                        .println("Errors were encountered while deleting "
12                                + r.getFullName());
13                for (Error e : r.getErrors()) {
14                    System.out.println("Error message: " + e.getMessage());
15                    System.out.println("Status code: " + e.getStatusCode());
16                }
17            }
18        }
19    } catch (ConnectionException ce) {
20        ce.printStackTrace();
21    }
22}

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.)

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.

Response

DeleteResult[]