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

3 Answers 3

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.
2
  • Might be worth explaining how to only query deleted rows for completeness.
    – Adrian Larson
    Commented Jun 1, 2016 at 16:26
  • 1
    @AdrianLarson Done :)
    – Mr.Frodo
    Commented Jun 2, 2016 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

3
  • i tried its showing Unknown error parsing query Commented Jun 1, 2016 at 7:50
  • Can we have both Isdeleted=true and ALL ROWS??
    – javanoob
    Commented Jun 1, 2016 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
    Commented Jun 1, 2016 at 8:44

You must log in to answer this question.

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