How to Select Archived Tasks and Events in SOQL

I recently encountered an issued where I could see a Task from within Salesforce.com, but I could not select it with the API. After some further research, I realized that it was qualified as an archived activity — that is, its ActivityDate field was more than 365 days old.

Unfortunately there’s no uniform way to select these through the API and on the platform. developerforce.com user Jayant pointed me at the ALL ROWS query append which enables these results to show up in apex, but if you attempt to run it from the api (Eclipse/Force.com IDE, AJAX Api, etc.), you’ll get a malformed query message similar to “ALL ROWS not allowed in this context”. You can use the queryAll() function instead of the simple query() function for the desired result in this context.

Remember that ALL ROWS and queryAll returns deleted records as well, so if you don’t want these, be sure to include isDeleted = false in your soql query.

This entry was tagged , , . Bookmark the permalink.