1

How i deleted parent account (which caused related event or task records deleted itself): I've run a batch, which do dml and send other sobject records to be dml in other batch from finish. I had to update the event and task records to assign a different parent account but the batch(failed) and finish continued to run another batch to delete their parent account(succeeded).

  • I used the Dynamic dml [Database.update(activitiesToUpdate, true) and Database.delete(accountsToDelete, true)]

I'm able to query those task and event records deleted implicitly with following soql

List<Task> tsks = [select id from task where isDeleted=true all rows];

system.assert(tsks.size()>0); //success

but unable to undelete them

undelete tsks; //throws an error that Those task record doesn't exist in recycle bin

FYI: i don't want to undelete parent account records, if it is required to undelete them can we remove the parent account id from record and then undelete, is this possible?

1 Answer 1

1

It's required to undelete the parent record. look:

If the records do not exist in the Recycle Bin, but they do exist when querying isDeleted = True in Data Loader, the records cannot be undeleted. However, they can be exported using Data Loader, and then recreated. Also, the deleted record could have been a Child record that was deleted because the Parent record is deleted. If this is the case, look for the parent record in the recycle bin then recover the parent record instead. This should automatically recover the deleted child records as well.

Also, it's not possible to undelete the Task changing it's parent.

Id deletedTaskId = '00T8b00008ACtW5EAL';
Id notDeleteAccountId = '0018b00002UvQ9SAAV';

Task t = new Task(Id=deletedTaskId,WhatId=notDeleteAccountId);

undelete t; // throws exception

If you don't want to undelete the parent and reassign the task, you can use the clone method

List<Task> newTasks = new List<Task>();
List<Task> deletedTasks = [SELECT Id, TaskSubtype From Task where isDeleted=true all rows]; // add all fields here
for (Task deletedTask : deletedTasks) {
  Task newTask = deletedTask.clone(false, true, false, false);
  newTask.WhatId = accId; //add your new account id
  newTasks.add(newTask);
}
insert newTasks;

You must log in to answer this question.

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