How do I delete records in the recycle bin?
Take a look at the Database.emptyRecycleBin(obj)
method or the other variants in the Database class such as Database.emptyRecycleBin(listOfSObjects)
For example, to permanently delete a contact with Id of '003i000000O4xYZ' in the recycle bin:
Contact c = new Contact(Id = '003i000000O4XyZ');
Database.emptyRecycleBin(c);
It is possible to hard delete using DataBase.emptyRecycleBin method in the Batch class. Create a sample Batch class as mentioned below and use DataBase.emptyRecycleBin method in the Batch class.
global class BatchDeletion implements Database.Batchable<sObject>, Schedulable{
global BatchDeletion(){}
global Database.QueryLocator start(Database.BatchableContext bc){
return Database.getQueryLocator([Select id from Account where Name='Test Account12']);
}
//Execute method for the Schedulable interface
global void execute(SchedulableContext sc){
//execute the batch
BatchDeletion deleteCS = new BatchDeletion();
ID batchprocessid = Database.executeBatch(deleteCS);
}
//Execute method for the batchable interface
global void execute(Database.BatchableContext BC, list<sObject> scope){
delete scope;
DataBase.emptyRecycleBin(scope);
}
global void finish(Database.BatchableContext BC){}
}
Note: 1. The DML operation datatbase.emptyRecycleBin is limited to 200 items, it is a known issue and currently no workaround is possible for this. http://success.salesforce.com/issues_view?id=a1p30000000STLXAA4