Query To undelete Bulk Records

Recently I had Faced This Issue:

My Records More Than 3-lakhs got deleted in Account object while running a query in Developer Console(Execute Anonymous Window)for multiple times.So I thought that I have only one way to  undelete it.By Going in to Recycle Bin undelete Records Individually.so that’s not Fair Idea to do it for More than 3Lakhs of Records.

Solution:

I got solution that this can be done by Coding.So I ran a query to check whether Retrieved Records are Correct.By running a Code maximum Limit of 10 Thousand Record is Retrieved.So I ran a query for 30+times to undelete the Records Completely.

List<Account> recordToUndelete= [SELECT Id, Name FROM Account WHERE
 IsDeleted = True AND LastModifiedDate = Today LIMIT 10000 ALL ROWS];

System.debug(recordToUndelete.size());
try
{
//attempt to undelete the records
undelete recordToUndelete;
}
//To Catch and Display DML Exceptions
catch(DMLException ex)
{
System.Debug(ex);
}
//To catch and Display Exceptions
catch(Exception e)
{
System.Debug(e);
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s