Get all Active and Deleted records salesforce

You are currently viewing Get all Active and Deleted records salesforce
Get all active and deleted records in apex

In this article you will learn how to get List of all present and deleted records from salesforce object using apex query.  Following code will retrieves deleted and present records from Account object.

				
					List<Account> records = [SELECT Id from Account ALL ROWS];
				
			

ALL ROWS keyword in a SOQL query retrieves all the records from the database, including those that have been deleted. 

The following code will return only deleted records from Account object.

				
					List<Account> deletedRec  = [SELECT Id from Account where isDeleted = true ALL ROWS];
				
			

Check out how to write a Trigger to permanently delete a record using emptyRecycleBin.

Leave a Reply