Query all objects (deleted and archived) in SOQL

Posted on 16-05-2013 09:02 by graham
When you perform a regular SOQL query, some records are omitted in the result set. This includes deleted objects, as well as archived ones. Sometimes, however, you might want to access them. This can be achieved using the ALL ROWS keyword at the end of your SOQL query.

The use of ALL ROWS

Let's say we are querying tasks in Salesforce. Tasks older than 365 days are automatically archived so they won't appear in the results of a normal query like this one:

To include them in the results, do:

This however will give us all records, including deleted and archived ones. Now, if we want to filter any of them, we can do this using the IsDeleted and Is Archived flag:
SELECT Id FROM Task ALL ROWS WHERE IsDeleted = false AND IsArchived = false


Add comment

Has this tutorial been helpful to you? Or do you see anything wrong? We appreciate your opinion!
Your comment:
Show formatting hints
HTML is disallowed, but in your text you can use the following markup
  • [code][/code] for a block of code
  • [tt][/tt] for inline code
  • [link]link href|link anchor[/link] for links
  • [b][/b] for bold text
+ Ask a question
If you have a technical question related to programming and computers, ask it here. Other users will help you solve it!
Unanswered questions
Share your knowledge by helping others solve their problems