+ Start a Discussion
RoyalRoyal 

RecycleBin ?

How to write a query on Recycle bin ?
like want to know how many records is there in recycle bin ..


Thanks


 
edoardo_spanoedoardo_spano
Hi,

you have to add ALL ROWS at the end of the query and the condition IsDeleted = true.

E.g.: [SELECT Id FROM Account WHERE IsDeleted = true ALL ROWS]
This query return all the accounts in the recycle bin.

Bye
ManojjenaManojjena
Hi ,

To get record including recycle bin you can write query like below  which will give you account including recyle bin .
 
List<Account> accList=[SELECT Id FROM Account ALL ROWS];
If you wnat account record only from recycle bin then you need to use below query .
 
List<Account> accList=[SELECT Id FROM Account  WHERE isDeleted = true ALL ROWS];

For more detail about All Rows please follow below link .

http://https://www.salesforce.com/us/developer/docs/apexcode/Content/langCon_apex_SOQL_query_all_rows.htm

Thnaks 
Manoj
 
RoyalRoyal
Hi Manoj,

In the second query if remove the ALL ROWS also will get Account records which is there in recycle bin, what is the use to adding here ALL ROWS  ?

and one more thing if i run the second query, getting error like "un konw error parsing query"  why ?

Thanks
ManojjenaManojjena
Hi Boyapati ,

Please check below comments it will clear all your doubts .

1.To get all accounts records  excluding recyclebin .
List<Account> accList=[SELECT Id,Name FROM Account ];
2.To get all account records including recyclebin .
  
List<Account> accList=[SELECT Id,Name FROM Account ALL ROWS ];
3.To get all account records only from recycle bin .    
List<Account> accList=[SELECT Id,Name FROM Account WHERE isDeleted = true ALL ROWS];
 NOTE :We cannot use the ALL ROWS keywords with the FOR UPDATE keywords.

Thanks
Manoj