---
schema_version: "1"
id: c1755c828c0632b37f09569c2907f0aea6dda4dbb2b373666c8c92ccfcd05220
title: deleteMetadata()
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/api_meta/meta_deleteMetadata.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_deleteMetadata.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: 83a4c67ee58f70f8e3d77e74963a93965254a77b7b1f3b5c2695413c8d56e914
description: Deletes one or more metadata components from your organization synchronously.
---
# deleteMetadata()

Deletes one or more metadata components from your organization synchronously.

## Syntax

[DeleteResult](https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_deleteResult.htm#meta_deleteResult "Contains result information for the deleteMetadata call.")\[\] = metadataConnection.delete(string metadataType, string\[\] fullNames);

## Usage

Use the deleteMetadata() call to delete any component that extends [Metadata](https://developer.salesforce.com/docs/atlas.en-us.264.0.api_meta.meta/api_meta/metadata.htm). All components must be of the same type in the same call. For more details, see [Metadata Components and Types](https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_objects_intro.htm "Metadata components are not based on sObjects, like objects in the API. Instead, they are based on metadata types, such as ApexClass and CustomObject, which extend Metadata, the base class for all metadata types. A component is an instance of a metadata type.").

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](https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_allornoneheader.htm "Indicates whether to roll back all metadata changes when some of the records in a call result in failures.") 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.

![Note](https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/images/icon_note.png)

#### Note

If a user requires access to metadata but not to data, enable the [Modify Metadata Through Metadata API Functions](https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_metadata_perm.htm "To use Metadata API, a user must have these things.") permission. Otherwise, enable 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](https://developer.salesforce.com/docs/atlas.en-us.264.0.object_reference.meta/object_reference/obj_ref_data_access.htm "HTML (New Window)") 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:

1. Determine the metadata type of the components you want to delete and the [fullName](https://developer.salesforce.com/docs/atlas.en-us.264.0.api_meta.meta/api_meta/metadata.htm#meta_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](https://developer.salesforce.com/docs/atlas.en-us.264.0.api_meta.meta/api_meta/metadata.htm) for more details on the [fullName](https://developer.salesforce.com/docs/atlas.en-us.264.0.api_meta.meta/api_meta/metadata.htm#meta_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

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

### metadataType

- **Type**: string
- **Description**: The metadata type of the components to delete.

### fullNames

- **Type**: string\[\]
- **Description**: Array of full names of the components to delete.
    
    Limit: 10. (For [CustomMetadata](https://developer.salesforce.com/docs/atlas.en-us.264.0.api_meta.meta/api_meta/meta_custommetadata.htm) and [CustomApplication](https://developer.salesforce.com/docs/atlas.en-us.264.0.api_meta.meta/api_meta/meta_customapplication.htm) 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.

## Response

[DeleteResult](https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_deleteResult.htm#meta_deleteResult "Contains result information for the deleteMetadata call.")\[\]