5

Question

Is there a simple way to query deleted records for quick and dirty data inspections?

Background

Doing this in Apex code or with integrations is fairly straight-forward just use the ALL ROWS key word in a SOQL query, or use the queryAll method in integrations.

However, if I just need to an ad-hoc query to find the deleted items, I'm at a lost to how to do this. If I do the query in the dev console or anonymous apex I get an error that ALL ROWS not permitted in this context. I've tried Dataloader.io, but it doesn't have any options I can find to export deleted records. I've also tried workbench, but I get the same ALL ROWS not permitted in this context.

The recycle bin works in some cases, but there are quite a few, e.g. Opportunity Line Items, scenarios where this doesn't work.

Is there really no good way to export deleted records without doing using some code to use the api queryAll method?

8

Actually, workbench is what you want. Easy to log in to, easy to use, quick and dirty query building, etc. Instead of adding ALL ROWS you just need to check the option to include archived and deleted records (the upper-right corner of the query editor)

For in-org access, consider writing a visualforce page that accepts a query that you can feed directly into database.query, or you could even build a GUI for it. You may also want to consider the Apex Data Loader. Unfortunately, you can't "report" on the recycle bin, so the options above are the most efficient in most cases.

|improve this answer|||||
  • Face palm, how did I miss that checkbox in workbench!! Thanks for pointing this out. – Ralph Callaway Jan 31 '14 at 21:14
  • 2
    @Ralph It's not a "bam, in your face" sort of feature. It just kind of hangs out there on the side, hoping you'll notice it. – sfdcfox Jan 31 '14 at 21:22
5

There are new methods in Database class from the Salesforce Release Winter 14(page 279), to get the deleted/updated records of an object at a specific time, Database.getDeleted and Database.getUpdated, i.e :

//simple example
Database.GetDeletedResult result  = Database.getDeleted(Merchandise__c',Datetime.now().addHours(-1),Datetime.now());
Database.DeletedRecord[] deletedRecords = result.getDeletedRecords();

I hope that can help

|improve this answer|||||
  • You still need to use execute anonymous, and read the logs to do that. ALL ROWS does the same thing, but lets you filter on other fields, too. They were looking for something "simpler." – sfdcfox Jan 31 '14 at 3:34
  • This is great to know the getDeleted method is now available in apex! Seems like workbench or dataloader would be simpler for some users who find this question later, but for me execute anonymous and debug logs is perfect. – Ralph Callaway Jan 31 '14 at 21:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.