delete()

Deletes one or more individual objects from your organization’s data.

Syntax

DeleteResult[] = sfdc.delete(ID[] ids);

Usage

Use delete() to delete one or more existing objects, such as individual accounts or contacts, in your organization’s data. The delete() call is analogous to the DELETE statement in SQL.

Rules and Guidelines

When deleting objects, consider the following rules and guidelines:

  • Your client application must be logged in with sufficient access rights to delete individual objects within the specified object. For more information, see Factors that Affect Data Access.
  • In addition, you might also need permission to access this object’s parent object. For special access requirements, see the object’s description in Standard Objects.
  • To ensure referential integrity, the delete() call supports cascading deletions. If you delete a parent object, you delete its children automatically, as long as each child object can be deleted. For example, if you delete a Case, the API automatically deletes any CaseComment, CaseHistory, and CaseSolution objects associated with that case. However, if a CaseComment is not deletable or is currently being used, then the delete() call on the parent Case will fail.
  • Certain objects cannot be deleted via the API. To delete an object via the delete() call, its object must be configured as deletable (deletable is true. To determine whether a given object can be deleted, your client application can invoke the describeSObjects() call on the object and inspect its deletable property.

Basic Steps for Deleting Objects

Deleting objects involves the following basic steps:

  1. Determine the ID of each object that you want to delete. For example, you might call query() to retrieve a set of records that you want to delete based on specific criteria.
  2. Construct an ID[] array and populate it with the IDs of each object that you want to delete. You can specify the IDs of different objects. For example, you could specify the ID for an individual Account and an individual Contact in the same array. For information on IDs, see ID Field Type.
  3. Call delete(), passing in the ID[] array.
  4. Process the results in the DeleteResult[] to verify whether the objects have been successfully deleted.

Sample Code—Java

public Boolean deleteSample() {
  // Create an array of Strings to hold the IDs of the records to delete and add IDs
  // to the array
  String[] ids = new String[] { "001x00000000JerAAE", "001x00000000JesAAE" };
  // Invoke the delete call
  try {
    DeleteResult[] deleteResults = binding.delete(ids);
    // Process the results
    for (int i=0;i<deleteResults.length;i++) {
      DeleteResult deleteResult = deleteResults[i];
      // Determine whether delete succeeded or had errors
      if (deleteResult.isSuccess()) {
        // Get the id of the deleted record
        deleteResult.getId();
      }
      else {
        // Handle the errors
        Error[] errors = deleteResult.getErrors();
        ...
      }
    }
  } catch (UnexpectedErrorFault e) {
    System.out.println("Unexpected error encountered:\n\n" + e.getExceptionMessage());
    return Boolean.FALSE;
  } catch (RemoteException e) {
    System.out.println("Remote exception encountered:\n\n" + e.getMessage());
    return Boolean.FALSE;
  }
  return Boolean.TRUE;
}

Sample Code—C#

private void deleteAccount()
{
   // Delete call takes a string array of Ids as parameter
   String[] IDs = new Sring[] {""};

   // Invoke the delete call, saving the result in a DeleteResult object
   DeleteResult[] deleteResults = binding.delete(IDs);

   // Determine whether the delete call succeeded or failed
   if (deleteResults[0].success)
   {
      // Delete operation succeeded
      System.Diagnostics.Trace.WriteLine("Deleted: " + deleteResults[0].id);
   } 
   else 
   {
      // Delete operation failed
      System.Diagnostics.Trace.WriteLine("Could not delete because: "
          + deleteResults[0].errors[0].message);
   }
}

Arguments

Name Type Description
ids ID[] Array of one or more IDs associated with the objects to delete. In version 7.0 and later, you can pass a maximum of 200 object IDs to the delete() call. In version 6.0 and earlier, the limit is 2,000.

Response

DeleteResult[]

Faults

InvalidSObjectFault

UnexpectedErrorFault

See Also:
API Call Basics
https://wiki.apexdevnet.com/index.php/Sample_SOAP_Messages
© Copyright 2000-2008 salesforce.com, inc. All rights reserved.
Various trademarks held by their respective owners.