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
Laurie HanlonLaurie Hanlon 

QueryAll returning records NOT in the recycle bin?



I am running some tests with queryall and am finding that it is returning records that have been deleted, but are NOT in the recycle bin.  This is primarily with Tasks, but I have come across it before with Contacts.  For example, I export all tasks where isdeleted=true, and I get 12 tasks.  I then attempt to undelete them (assuming they should be in the recycle bin) and I get errors that they are no longer in the recycle bin.  Plugging in the ID to the SF URL, it does confirm the records are deleted.


So...I think I have narrowed it down to 2 possibilities:


1.  Hard Deleted Records - The docs all say they do not go to the recycle bin (and yes they are not there as expected), but they ARE flagged with isdeleted=true, so they can be exported with queryall().  I have tested hard deleting some Tasks and Leads and WAS able to export them with queryall.


2.  Cascading Deletes - When a child record is deleted when the parent is deleted (i.e. Tasks when the Lead is deleted), the Task records ARE also flagged with isdeleted=true, but again are not directly in the recycle bin, and they ARE exported with queryall().


So it appears that the SF help documentation around isdeleted is INCORRECT unless I am missing something


Indicates whether the object has been moved to the Recycle Bin (true) or not (false). Label is Deleted.


The assumption based on the SF docs for the isdeleted field would be that any records that can be exported with queryall should be able to be undeleted using the undelete() call, but that is not true in these cases.


Also I am assuming that once a record is flushed from the recycle bin, then it can no longer be queried qith query(all).  The docs do not seem to clarify this either "Indicate where the object has been MOVED to the recycle bin" vs. is IN the recycle bin.


Can anyone confirm my findings?  


Thanks, Laurie




Hi Laurie, 


Internally it is also described as Marked for Deletion which will not be undeleted but the task is on the Salesforce database internally to keep clearing the records. 

See below for more info.







I am new to Salesforce myself, I believe there are some security implications which works around the Recycle Bin in Salesforce. I read somewhere that there is a "Modify All Data" or something like that which allows the user to see "My Recycle Bin" or "All Recycle Bin". It could be that the user deleting the record or record owner govern the ability of viewing or bringing back the data which has been deleted (as per the security permissions that might have).


I did use partner.wsdl to do a QueryAll Method call with SOQL "select id, name from contact where isDeleted=true" and it showed me the records I deleted. I then tried to undelete them through the unDelete Call and they where undeleted. However, I tried the same by switching between users who do not have permission and it showed no records.


As I said, I am new to this, and there could have a cool idea behind, but I suspect  that there is a logic for sure behind this and not a bug or mis-documentation.