[SalesForce] How to delete records in the recycle bin

I understand that when I perform a Database.delete() operation, records will end up in my org's recycle bin. And their presence in the recycle bin is reflected by the IsDeleted field on the object.

But if those records are (for example) scrapes of a web page, they are of little interest to users and I don't want them kicking around in the org. Currently the only way I can see to 'hide' them would be to misuse a Protected (List) Custom Setting object.

From Apex, how can I delete a record and skip this, so it doesn't clutter a user's recycle bin?

Best Answer

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);
Related Topic