Wednesday 18 June 2014

How to get deleted records from recylebin and restore them to database

We need to use ALL ROWS keyword in soql query.
ALL ROWS keywords need to be used to query all records in an organization, including deleted records( records in your organization's Recycle Bin) and archived activities. 

You cannot use the ALL ROWS keywords with the FOR UPDATE keywords. 


list<Account> listOfAccounts = [SELECT id,Name FROM Account WHERE isDeleted = true ALL ROWS];

undelete listOfAccounts ;


isDeleted:- It is a standard field of account used to differentiate whether account is in Recycle Bin or not. 

undelete:- Its a DML Operation.


FOR UPDATE:Keywords used in SOQL to lock an sobject records and preventing from being updated. 
P.S.:- ORDER BY and FOR UPDATE keywords in any SOQL can not be used together.

1 comment:

Anonymous said...

Hey,

How can i retrieve the records deleted by specific person?
Is it by using DeletedBy?