+ Start a Discussion
Dave The RaveDave The Rave 

Recycle Bin + add fields

I understand that you cannot add fields to the recycle bin page for a specific tab. 

I would like to retrieve deleted records from the CASE object which have a specific recordtype. 

I tried to do this in the Developer Console with SOQL but this still does not work.

I read that you need to de an SOQL All Query, I am an administrator.
Can somebody help me out here? 

Thanks,

Dave
Best Answer chosen by Dave The Rave
JayantJayant
ALL ROWS only works in Apex.
You may try in Anonymous Apex window.

List<Case> deletedCases = new List<Case>();
deletedCases = [SELECT Id FROM Case WHERE IsDeleted = TRUE AND RecordType.DeveloperName = 'ICTSupport' ALL ROWS];
system.debug('\nNumber of deleted cases is :\t' + deletedCases.size() + '\nand the cases are :\n' + deletedCases);

All Answers

JayantJayant
Your query should be using the ALL ROWS clause and queried fields should include the IsDeleted standard field. for e.g.
SELECT Id, CaseNumber, Subject, AccountId, isDeleted FROM Case ALL ROWS

From the dataset that returns, all records that have the isDeleted as TRUE are the ones that reside in the Recycle Bin. Collect Ids of all such records in a list of Cases and perform an Undelete DML on that list.

If you just want to query the records from Recycle Bin, you can add a query filter. For e.g.
SELECT Id, CaseNumber, Subject, AccountId, isDeleted FROM Case WHERE IsDeleted = TRUE ALL ROWS

Maybe this is the ideal query for you (since it just retrieves records from Recycle Bin and minimum information that must be retrieved) - 

SELECT Id FROM Case WHERE IsDeleted = TRUE ALL ROWS

You're done.
Dave The RaveDave The Rave
SELECT Id FROM Case WHERE IsDeleted = TRUE ALL ROWS

I copied this into the "Query Editor" in the Dev Console and got an error:

"Unknown error parsing query"

I am only looking to view the deleted case, also with RecordType = 'ICTSupport'
JayantJayant
ALL ROWS only works in Apex.
You may try in Anonymous Apex window.

List<Case> deletedCases = new List<Case>();
deletedCases = [SELECT Id FROM Case WHERE IsDeleted = TRUE AND RecordType.DeveloperName = 'ICTSupport' ALL ROWS];
system.debug('\nNumber of deleted cases is :\t' + deletedCases.size() + '\nand the cases are :\n' + deletedCases);
This was selected as the best answer
Dave The RaveDave The Rave
Hi Jayant, the code does work in the Anonymous Apex window and you have to make should you tick the 'open logs' tickbox. One question I have is does this only show the number of records that I deleted or for the entire SF org? and can I make a list of the cases and show specific field values in columns, just like the display you get as a result of an SOQL query?
JayantJayant
It shows records deleted by everyone in your Org, if you are an administrator. If you want to find out the user who actually deleted the record, LastModifiedBy field would hold that user's id while the record resides in recycle bin. Yes, you can query these records and display them in VF or Lightning Component as usual.
So once retrieved they are just a regular list and you can do whatever you are allowed to do with lists except delete DML again, you can undelete though :).

By the way, Salesforce just holds the most recent 5000 records deleted in the Recycle Bin across users, if a record would cause the number to go beyond 5000, the oldest record in Recycle Bin would be purged to make way for this new entrant.

Also, several standard objects (though the niche ones) never get into Recycle Bin and are always hard deleted. Similarly any records deleted using Hard Delete option available on Apex Data Loader using Bulk API would never make to Recycle Bin. 
Dave The RaveDave The Rave
Hi Jayant, thanks for your answers. Just one more question, in the system debug, I can see the ID's of the deleted records, which is great. Is it possible to see CaseNumber also?
JayantJayant
Just change
[SELECT Id FROM Case WHERE IsDeleted = TRUE AND RecordType.DeveloperName = 'ICTSupport' ALL ROWS];
to
[SELECT Id, CaseNumber FROM Case WHERE IsDeleted = TRUE AND RecordType.DeveloperName = 'ICTSupport' ALL ROWS];

You may include as many fields as you want.