Problem:
When trying to restore a Merge, the restore only partly succeeds. Sometimes an error message is shown, similar to:
“C0000240 npsp:Too many SOQL queries: xxx”
Where xxx is a number of 100 or up.
Answer:
When undoing a merge, sometimes a large number of related records needs to be restored, for example because the merged records contained related records from many different objects such as contacts, tasks, activities etc. In these situations the process to restore the related records can exceed the Salesforce Governor Limit.
To make sure that at least the most important records are restored, solve this, order the related objects that are being tracked for restoring by importance. Read more in Setting Tracked Related Objects.
Note that even if you were to track only one related object, errors can still occur if the total number of related records is too large. In that case you will most likely see a DML error instead.
Read more about the different reasons why undoing a merge can fail in Undoing a merge didn't work.