7

I have mistakenly deleted 200,000 records in the recycle bin and am trying to recover them. Although, clicking undelete button 1000 times might be a good way of remembering the mistake, it is still a bit too time consuming. Is there a way to mass undelete the data?

I have looked at workbench and it does have the undelete functionality. But the question is how can I get the list of Ids which have been deleted?

I have tried:

Select Id, name
From Matter_Sitting__c 
Where isDeleted = true

But it doesn't seem to work.

1 Answer 1

8

Use database class and from Developer Console try Execute anonymous window

Database.Undelete(recordIDs, allOrNone);

Restores one or more existing sObject records, such as individual accounts or contacts, from your organization’s Recycle Bin.

SOQL statements can use the ALL ROWS keywords to query all records in an organization, including deleted records and archived activities. For example::
You can use ALL ROWS to query records in your organization's Recycle Bin. You cannot use the ALL ROWS keywords with the FOR UPDATE keywords.

Ref: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_SOQL_query_all_rows.htm

List<Sobject> SobjectList = [SELECT ID FROM Sobject WHERE IsDeleted = TRUE LIMIT 100 ALL ROWS];

Ref: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_database.htm

5
  • Thank you for this. But the question again is how do I query the list of deleted items' Id list?
    – Lance Shi
    Commented Mar 7, 2017 at 4:08
  • use From ALL ROWS,I have updated my answer. Commented Mar 7, 2017 at 4:09
  • That will be over the governor limit though - total number of records returned. Should I be using limit and offset in this case?
    – Lance Shi
    Commented Mar 7, 2017 at 4:16
  • 9
    @LanceShi undelete [SELECT Id FROM Matter_Setting__c WHERE IsDeleted = TRUE LIMIT 1000 ALL ROWS];
    – sfdcfox
    Commented Mar 7, 2017 at 4:39
  • Thanks @sfdcfox I was about to comment that but lost my internet connection ! Commented Mar 7, 2017 at 5:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .