Newer Version Available
delete()
Syntax
1AsyncResult[] = metadataConnection.delete(Metadata[] metadata);Usage
Use this call to delete one or more components from your organization.
Version
This call is available in API version 30.0 and earlier only. This call is not available in API version 31.0 and later. Use deleteMetadata() instead.
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's 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:
- Determine the fullName of each component you want to delete. See Metadata for more details on the fullName field. You can only delete components of the same type in a single call.
- Invoke the delete() call, passing in the array of metadata components with fullName specified.
- An AsyncResult object is returned for each component you try to delete, and is updated with status information as the operation moves from a queue to completed or error state. Call checkStatus() in a loop until the status values in AsyncResult indicate that all the delete operations are completed. Start with a wait time of one second between iterations of checkStatus() calls, and double the wait time each time you make a subsequent call.
Sample Code—Java
1public void deleteCustomObject() {
2 try {
3 CustomObject co = new CustomObject();
4 co.setFullName("MyCustomObject__c");
5 AsyncResult[] ars = metadataConnection.create(new Metadata[]
6 {co});
7 AsyncResult asyncResult = ars[0];
8 long waitTimeMilliSecs = 1000;
9 while (!asyncResult.isDone()) {
10 Thread.sleep(waitTimeMilliSecs);
11 // double the wait time for the next iteration
12 waitTimeMilliSecs *= 2;
13 asyncResult = mdConnection.checkStatus(
14 new String[] {asyncResult.getId()})[0];
15 System.out.println("Status is: " + asyncResult.getState());
16 }
17 } catch (ConnectionException ce) {
18 ce.printStackTrace();
19 } catch (InterruptedException ie) {
20 ie.printStackTrace();
21 }
22}Arguments
| Name | Type | Description |
|---|---|---|
| metadata | Metadata[] |
Array of one or more metadata components. You only need to set the fullName field in the Metadata object. You must submit arrays of only one type of component. For example, you could submit an array of 10 custom objects or 10 profiles, but not a mix of both types. |