function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Cannot test emptyRecycleBin

I'm trying to verify that my code is permanently deleting objects.  For some reason, the test still finds the newly inserted tasks when I query ALL ROWS -even though I just purged it from the recycle bin.  Any ideas how I can test that a record was purged from the recycle bin successfully?


Any help is appreciated,




Here's my test code:


	static testMethod void testPermanentDelete()
		Task t = new Task(
			Subject = 'subject',
			Priority = 'Normal',
			Status = 'Completed',
			ActivityDate =;
		insert t;
		Id taskId = t.Id;
		//Verify the task was inserted
		List<Task> foundTasks = [Select Id From Task Where Id = :taskId ALL ROWS];
		System.assertEquals(1, foundTasks.size());
		Database.DeleteResult[] deleteResults = Database.delete(foundTasks, false);
		Database.EmptyRecycleBinResult[] emptyRecycleBinResults = Database.emptyRecycleBin(foundTasks);
		//Verify the task was permanently deleted
		foundTasks = [Select Id From Task Where Id = :taskId ALL ROWS];
		System.assertEquals(0, foundTasks.size());



I would try checking the deleteResults and the emptyRecycleBinResults have isSuccess = true, because one of those may be failing (and the database methods don't throw an exception that yo uwould see in your test result)

Andrew B. DavisAndrew B. Davis
According to this Stackexchange article (, even if you empty the recycle bin, those records may still appear when you query ALL ROWS. Apparently ALL ROWS also queries rows that are queued waiting for Salesforce to delete them, even if they are no longer in the Recycle Bin. Confusing behavior, and I don't know if there is a method to write test routines to confirm that the recycle bin is empty.
J BengelJ Bengel
It's six years later, and I have this same quesiton. Every piece of documentation I can find on the subject sends you down the path of querying ALL ROWS on the object where isDeleted = true, but that would be true whether the record was in the recycle bin or not -- until the garbage collector runs and purges the records that were permanently deleted. That query would confirm that the records are deleted (in this case from ContentDocument) but not that they have been removed from the recycle bin. I can go to the Recycle bin and see that it worked, but I can't test it from my test class.