Play Games

Search This Blog

Saturday, May 7, 2022

How to fetch the deleted record in soql query - salesforceglobe4u

How to fetch the deleted record in soql query - salesforceglobe4u

Solution: Use the ALL ROWS keyword at the end of SOQL query to fetch deleted records as well as shown below

select id,name from Account where isdeleted=:true ALL ROWS

Example:

Run the following piece of code in execute anonymous window of Developer Console

List<Account> lstAccount = new List<Account>();

lstAccount = [select id,name from Account where isdeleted=:true ALL ROWS];

system.debug('Number of Accounts: '+lstAccount.size());

for(Account acc :lstAccount) {

system.debug('Account Name: '+acc.Name);

}

Output:

before deleting Nikhil Account you get 0 records in query


After deleting Nikhil Account


No comments:

Post a Comment