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
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]
Use ALL ROWS
keyword in SOQL.
[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:
ALL ROWS
keyword seems to work perfectly with apex code(Or maybe with Workbench) but not in query editor(Developer console)- 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 ♦Commented Jun 1, 2016 at 16:26
-
1
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
-
-
-
Hi Vipin and Javanoob, I have updated my answer and removed the ALL ROWS. I have also mentioned the Salesforce doc that I referred. Commented Jun 1, 2016 at 8:44