function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Swamy P R NSwamy P R N 

How to undelete the records by deleted date (or) deletedBy

Hello Everyone,

In my system there are 2 laksh records, in that 5000 records are deleted by user1. Now i want to undele only those 5000 records which are deleted by user1. How can i build the query for that. Also is it possible to un-delete the records by record deleted date. 

Thanks Much.
Himanshu ParasharHimanshu Parashar
Hi Swamy,

There is no way to find who deleted that record but lastmodifiedbyid field store who modified that record at the end so you can use that field to identify.

Following query will work for you.
List<Account> lstAcc=[SELECT id,IsDeleted,LastModifiedDate FROM Account WHERE IsDeleted = true and LastModifiedDate=:TODAY ALL rows];

undelete lstAcc;

Swamy P R NSwamy P R N
Hi Himanshu,

When we delete the record, is it going to change the lastmodifieddate to recrd deleted datetime. If yes, than we can query the records as you mentioned. Otherwise we have to query in another way.

Are we have deleted datetime API. If it is avialable than we can query the rows which are deleted Today.
Himanshu ParasharHimanshu Parashar
Hi Swamy, 

Yes it change lastmodifieddate once you delete that.