I did the following

1)Deleted a record in sfdc and then ran the query using ' ALL ROWS' keyword and i could see that as per the documentation that data from recycle bin is also retrieved with isdeleted=true

2)I deleted the record from recycle bin and now i observed that still i was able to retrieve it .

Can anybody aware why this happens ?

Also if i filter the records by date and use ALL ROWS will the date filter still apply?

1 Answer 1


Documentation around the Database.emptyRecycleBin (which essentially is what happens when you click the button in the Recycle Bin too) says "After records are deleted from the recycle bin using this call, they can be queried using queryAll() for some time. Typically this time is 24 hours, but may be shorter or longer."

(added after the comment about REST API:) Visibility of stuff in the Recycle Bin doesn't look like something we have control over. If you can somehow expose this function to your REST app (by wrapping a piece of Apex like here) you could "hard delete" your records. But even then they'll stay visible, you'll just guarantee receiving DMLException if anybody tries to undelete them.

And yes, you can mix filtering by date fields, isDeleted and ALL ROWS.

SELECT Id, isDeleted, LastModifiedBy.Name, LastModifiedDate FROM Account WHERE CreatedDate = TODAY ALL ROWS and for deleted records LastModifiedBy will mean who & when has deleted them while for "normal" ones it will be last update.

I must say I'm a bit confused. Please write up more about your actual requirements? Essentially - do you want to show items in recycle bin or not :)

Edit again ;)

Sounds like most natural cut for your situation was done by smart guys at SF already.

1 normal query that gets all creates & updates

SELECT (all the fields you need) FROM Obj WHERE LastModifiedDate >= :lastUpsertSync

And another! query for deletes (you need only basic info that item was deleted after all, no need to retrieve details, right?)

SELECT Id FROM Obj WHERE isDeleted = true AND LastModifiedDate >= :lastDeleteSync ALL ROWS

If you're afraid you'll hit heap size limits or count of rows - simply add something like ORDER BY LastModifiedDate ASC LIMIT 1000 clauses to both queries. Then whenever one of queries returns exactly 1000 you'll know there's risk you haven't retrieved full set. Then modify the variable that holds for example lastDeleteSync to value from last row and rerun the sync, ask user to hit the button again or whatever. Even better - use the queryLocator's id to retrieve next set of results (but before your session expires).

  • Ya thanks removed the FOR from qestion.I tried after one day also and it remained same .So worried that it will keep adding.Also my app logics planned wont allow me to use emptyRecycleBin.Thanks for your reply.Looking for some more answers from all Commented Nov 4, 2012 at 16:11
  • Thanks again.unfortunately my app is mobile app using IOS SDK uses objective C .So do we have any RestApi calls ? Commented Nov 4, 2012 at 16:33
  • App is designed for offline sync.I query for all records thats been modified or deleted or created after the last sync and indicate via a flag which is D for deleted,U for updated and C for created only after the last sync .I am afraid that if deleted records keep coming in output JSON then i will reach the 50000 query rows limit also may be i will reach heap size before that.Also once deleted from the salesforce we just delete in app and we expect no more undletes happen in browser .Anyways thanks for your help Commented Nov 4, 2012 at 17:05
  • Thanks for the reply.Can i not merge both queries here.Last Synced time will be same for upserts and deletes.I can reduce an SOQL .Thanks.Looking for more answers from rest of community and if i dont i will mark as ticked.Thanks Commented Nov 5, 2012 at 7:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .