Hello Everyone, In this tutorial, I am going to show you, how you can query deleted records from recycle bin in Salesforce. so without wasting the time let's get started,

Query deleted records in Salesforce

In some cases when performing a SOQL query, some records are not appearing in the query results because this query not included deleted and archived records. For example, Task more than a year old (365 days) are automatically disappear when we query data in Salesforce without using “ALL ROWS” keyword.

You can use ALL ROWS keyword in SOQL statements to query all records in an organization, including deleted records and archived activities.

Example:
 List<Account> lstAccount=[SELECT Id,Name FROM Account ALL ROWS];
 System.debug('^^^'+lstAccount);
Note: "ALL ROWS" keyword can’t use with "FOR UPDATE" keyword.


See also:

Conclusion:
Hope you like this tutorial, for any query or suggestions please feel free to comment.
Thank you.