Wednesday, November 22, 2023

To get recycle bin records in SOQL

 In Salesforce Object Query Language (SOQL), there isn't a direct query to retrieve records from the Recycle Bin. The Recycle Bin is a system feature that retains deleted records for a certain period before they are permanently deleted. SOQL queries only operate on active records, and the Recycle Bin is not directly queryable.

However, you can use the ALL ROWS keyword to include records that are in the Recycle Bin in your query results. Here's an example:

To return only the deleted rows.     SELECT Id, isDeleted FROM <Oblectname> WHERE isDeleted = true All ROWS To return only the archived rows.     SELECT Id, isDeleted FROM <Oblectname> WHERE isArchived = true All ROWS To return the deleted records, archived records and records that are     SELECT Id, isDeleted FROM <Oblectname> All ROWS

Replace YourObject__c with the actual API name of the object you are interested in. The IsDeleted field will indicate whether the record is in the Recycle Bin (true) or not (false).

Keep in mind that querying records from the Recycle Bin can return a large number of records, so it's important to use appropriate filters in your query to limit the results. Additionally, querying records from the Recycle Bin counts against your query limits just like querying active records.

No comments: