10

Looking for a SOQL query (or some other method) to get a count of records in my orgs recyclying bin. I have seen other solutions posted suggesting to use the IsDeleted = TRUE and ALL ROWS to the SOQL statement, but these all involve querying a specific object (i.e. FROM Account). I need a count of ALL records in the recycling bin. Thanks if possible.

3

It is impossible to query records from different subject types. Therefore the database class implements several methods to delete "specific" records.

Potential solution

Map<String, Schema.SObjectType> globalDescription = Schema.getGlobalDescribe();
Integer counter = 0;
for(String key : globalDescription.keyset())
{
    counter += Database.getDeleted(key, DateTime.now().addYears(-1), DateTime.now()).getDeletedRecords().size();
}

I'm not 100% sure but it looks like there is no limit for Database.getDeletedmethod calls.

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.