sforce logo

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:

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.
  3. Call delete, passing in the ID[] array.
  4. Process the results in the DeleteResult[] object to verify whether the objects have been successfully deleted.

Sample Code-Java

public void deleteSample() { 
 
   // Create an array of IDs to hold the IDs of the records to delete 
   ID[] ids = new ID[2]; 
 
   // Add the IDs to the ID array 
   ids[0].setValue("001x00000000JerAAE"); 
   ids[1].setValue("001x00000000JesAAE"); 
 
   // Invoke the delete call 
   DeleteResult[] deleteResults = binding.delete(tasks); 
   // 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(); 
      } 
   } 
} 

Sample Code-C#

private void deleteAccount() 
{ 
   // Delete call takes an 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("Couldn't 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. The sforce Web service deletes these objects in array index order. You can pass a maximum of 2000 object IDs to the delete call.

Response

DeleteResult[]

Fault

InvalidSObjectFault

UnexpectedErrorFault

See Also

Sample SOAP Messages-delete

Concepts


© Copyright 2000-2003 SalesForce.com, Inc.
All rights reserved • Various trademarks held by their respective owners.