delete()
Deletes one or more records from your organization’s data.
Use delete() to delete one or more existing records, such as individual accounts or contacts, in your organization’s data. The delete() call is analogous to the DELETE statement in SQL.
When deleting objects, consider these 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 could 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 being used, then thedelete()call on the parent Case fails. -
Certain objects cannot be deleted via the API. To delete an object via the
delete()call, its object must be configured as deletable (deletableistrue) . To determine whether a given object can be deleted, your client application can invoke thedescribeSObjects()call on the object and inspect itsdeletableproperty. -
You can’t delete records for multiple object types in one call if one of those types is related to a feature in the Setup area in Salesforce. The only exceptions are these objects.
- Custom settings objects, which are similar to custom objects. For more information, see Create Custom Settings in Salesforce Help .
- GroupMember
- Group
- User
The AllOrNoneHeader header allows you to roll back all changes unless all records are processed successfully. This header is available in API version 20.0 and later. Lets a call roll back all changes unless all records are processed successfully.
Deleting records involves these basic steps.
- Determine the ID of each record that you want to delete. For example, you call
query()to retrieve a set of records that you want to delete based on specific criteria. - Construct an ID[] array and populate it with the IDs of each record that you want to delete. You can specify the IDs of different types of objects in the same call. 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.
- Call
delete(), passing in the ID[] array. - Process the results in the
DeleteResult[] to verify whether the records have been successfully deleted.
This sample shows how to delete records based on record IDs. The method in this sample accepts an array of IDs, which it passes to the delete() call and makes the call. It then parses the results and writes the IDs of the deleted records to the console or the first returned error if the deletion failed.
This sample shows how to delete records based on record IDs. The method in this sample accepts an array of IDs, which it passes to the delete() call and makes the call. It then parses the results and writes the IDs of the deleted records to the console or the first returned error if the deletion failed.
| 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. |
See Also