Newer Version Available
emptyRecycleBin()
Syntax
1EmptyRecycleBinResult[] = connection.emptyRecycleBin(ID[] ids);Usage
The Recycle Bin lets you view and restore recently deleted records for 15 days before they’re permanently deleted. Your org can have up to 5,000 records per license in the Recycle Bin at any one time. For example, if your org has five user licenses, 25,000 records can be stored in the Recycle Bin. If your org reaches its Recycle Bin limit, Salesforce automatically removes the oldest records, as long as they’ve been in the recycle bin for at least two hours.
If you know you’re adding a great number of records to the Recycle Bin, and you don’t want to undelete() them, you can remove them before the Salesforce process deletes records. For example, you can use this call if you’re loading a large number of records for testing, or if you’re doing a large number of create()calls followed by delete() calls.
Rules and Guidelines
When emptying recycle bins, consider the following rules and guidelines:
- The logged in user can delete any record that they can query in their Recycle Bin, or the recycle bins of any subordinates. If the logged in user has Modify All Data permission, they can query and delete records from any Recycle Bin in the organization.
- Available in version 10.0 and later.
- The maximum number of records is 200.
- Don’t include the IDs of any records to be cascade deleted, or an error occurs.
- After records are deleted using this call, they can’t be undelete().
- After records are deleted from the Recycle Bin using this call, they can be queried using queryAll() for some time. Typically this time is 24 hours, but can be shorter or longer.
Sample Code—Java
This sample shows how to empty the Recycle Bin. It accepts an array containing the IDs of the records to remove from the Recycle Bin. It calls emptyRecycleBin() and passes it the array of IDs. Next, it iterates over the results and writes the IDs of the removed records or the first error of the failed records to the console.
1public void emptyRecycleBin(String[] ids) {
2 try {
3 EmptyRecycleBinResult[] emptyRecycleBinResults = connection
4 .emptyRecycleBin(ids);
5 for (int i = 0; i < emptyRecycleBinResults.length; i++) {
6 EmptyRecycleBinResult emptyRecycleBinResult = emptyRecycleBinResults[i];
7 if (emptyRecycleBinResult.isSuccess()) {
8 System.out.println("Recycled ID: "
9 + emptyRecycleBinResult.getId());
10 } else {
11 Error[] errors = emptyRecycleBinResult.getErrors();
12 if (errors.length > 0) {
13 System.out
14 .println("Error code: " + errors[0].getStatusCode());
15 System.out
16 .println("Error message: " + errors[0].getMessage());
17 }
18 }
19 }
20 } catch (ConnectionException ce) {
21 ce.printStackTrace();
22 }
23}Sample Code—C#
This sample shows how to empty the Recycle Bin. It accepts an array containing the IDs of the records to remove from the Recycle Bin. It calls emptyRecycleBin() and passes it the array of IDs. Next, it iterates over the results and writes the IDs of the removed records or the first error of the failed records to the console.
1public void emptyRecycleBin(String[] ids)
2{
3 try
4 {
5 EmptyRecycleBinResult[] emptyRecycleBinResults =
6 binding.emptyRecycleBin(ids);
7 for (int i = 0; i < emptyRecycleBinResults.Length; i++)
8 {
9 EmptyRecycleBinResult emptyRecycleBinResult = emptyRecycleBinResults[i];
10 if (emptyRecycleBinResult.success)
11 {
12 Console.WriteLine("Recycled ID: "
13 + emptyRecycleBinResult.id);
14 }
15 else
16 {
17 Error[] errors = emptyRecycleBinResult.errors;
18 if (errors.Length > 0)
19 {
20 Console.WriteLine("Error code: " + errors[0].statusCode);
21 Console.WriteLine("Error message: " + errors[0].message);
22 }
23 }
24 }
25 }
26 catch (SoapException e)
27 {
28 Console.WriteLine("An unexpected error has occurred: " +
29 e.Message + "\n" + e.StackTrace);
30 }
31}