5

I have 10 Contact which are showing in my vfpage..suppose i'll delete 3 record then its show only 7 record on vfpage. i want to also show deleted record which was gone into recyclebin. what is the soql query or any keyword to show deleted record data on tha vfpage

7

In your Query Append with ALL ROWS. It will include the Deleted Records too...

Like below Query

[SELECT COUNT() FROM Contact WHERE AccountId = a.Id ALL ROWS]
7

Use ALL ROWS keyword in SOQL.

Documentation

[SELECT COUNT() FROM Contact WHERE AccountId = a.Id ALL ROWS]

To retrieve only deleted records

[SELECT COUNT() FROM Contact WHERE isDeleted=True ALL ROWS]

Note:

  1. ALL ROWS keyword seems to work perfectly with apex code(Or maybe with Workbench) but not in query editor(Developer console)
  2. These queries returns the rows which are even deleted from recycle bin(For a limited time period) too so keep that in mind.
  • Might be worth explaining how to only query deleted rows for completeness. – Adrian Larson Jun 1 '16 at 16:26
  • 1
    @AdrianLarson Done :) – Mr.Frodo Jun 2 '16 at 10:52
2

To query items that are in the recycle bin, just construct a query on any object where IsDeleted=1. Like for querying deleted reports you can write a query like this - [SELECT Id,Name FROM Account WHERE IsDeleted = true].

Please refer to this link from Salesforce for more details. https://help.salesforce.com/apex/HTViewSolution?urlname=How-to-retrieve-my-records-and-data-that-has-been-lost-or-deleted-1327108681812&language=en_US

  • i tried its showing Unknown error parsing query – Vipin Indora Jun 1 '16 at 7:50
  • Can we have both Isdeleted=true and ALL ROWS?? – javanoob Jun 1 '16 at 8:35
  • Hi Vipin and Javanoob, I have updated my answer and removed the ALL ROWS. I have also mentioned the Salesforce doc that I referred. – Saroj Bera Jun 1 '16 at 8:44

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.