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
gtindugtindu 

Undelete on a record with Master-Detail relationships...

We are running into issues with undeleting Opportunities with a master-detail relationship to a child object... and there can be many children records...

When actually undeleting (from apex or from recycling bin) - we'll ALWAYS get "Too Many SOQL Queries"... it orginates from our BeforeUpdate trigger on the child record.  It appears all of the children are being processed individually through the trigger instead of batched...

 

So even if we only had 1 SOQL query - 20 children records - and we're broken again... and it isn't calling the undelete trigger action on the child records - its calling Before/After Update... so theres no way to skip processing.

 

Am I missing something? Surely this isn't working as intended.

Ispita_NavatarIspita_Navatar

You have to do 2 things:-

1. Please check if your trigger is getting caught in recurrsive calls

2. If there is a SOQL query being fired in a loop

Also check if you trigger code is optmised.

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.

 

gtindugtindu

It's not caught in a loop -

It seems to be instead firing Before/After Update for each detail record associated with the undelete, but instead of a batch - it's firing them 1 at a time...

 

This is apparently the default functionality for the recycle bin... If I however open up System Log and do the following it works without issue:

undelete new List<Opportunity>([SELECT Id FROM Opportunity WHERE IsDeleted = true AND Id = '006XXXXXXXXXXXX']);

 

I can even batch it together if i setup a list of Ids for records that fail within the recycle bin for too many SOQL Queries.... and the code executes in system log without fail, and appropriately batches everything....

SO PAINFUL.  It makes it impossible for some users to recover anything from the recycling bin - instead they have to escalate.