[SalesForce] Retrieving data from recycle bin

After I deleted a record from recycle bin, and I run this in Anonymous;

System.debug(database.query('select id,name from Candidate__c where id=\'a012800000Gs7IG\' all rows'));

I am able to see the record.

Can anyone tell me how long a data will live after getting deleted from recycle bin ??

or

the effect of deleted records from recycle bin will work after some time from the moment it is deleted from recycle bin ? i.e. after a day or two I won't get any result from this query. Because even now I see my recycle bin is empty.

Best Answer

You can delete records from the recycle bin by using the Database.emptyRecycleBin method:

Database.emptyRecycleBin([
    SELECT Id FROM Candidate__c WHERE Id = 'a012800000Gs7IG' ALL ROWS
]);

If your record is still in the recycle bin after calling the above, you should open a ticket with support. You can also hard delete via the Bulk API if you enable it as an option.

See also: How can I permanently delete a record whose isdeleted="true", and specifically this knowledge article for details:

Record data has 3 stages of deletion:

Stage 1 - Deleted to Recycle Bin - Data in this stage can still be recovered from the recycle bin. This can also be referred to as soft deleted.

Stage 2 - Emptied from the Recycle Bin or hard deleted - Data in this stage cannot be recovered from the recycle bin but can be accessed and exported from the API using Export All (queryall) in DataLoader v21 and higher or other api tools. Records can also be put in this state directly by using the hard delete option in the Data Loader.

Stage 3 - Physically/Permanently deleted - Data in this stage has been wiped from database and only recoverable by contacting Salesforce to request a Data Recovery Service (fee associated). Please click here to learn more about the Data Recovery Process.

Related Topic