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
Mehmet_ErgunMehmet_Ergun 

after trigger query

If you delete a parent record, all lookup-children are orphaned.  (Not master-details).

The lookup field to the parent from the child is simply nulled out.

 

So if you wanted to run a query that retreived the records orphaned from that particular parental delete, and you wanted to do it only in an after-delete trigger (not before), how would you do it?

 

 

Message Edited by Mehmet_Ergun on 05-29-2009 11:56 AM
ShikibuShikibu

I think that you should be able to use the "old" trigger context variable.

 

 

ahab1372ahab1372

find the IDs of the children through the deleted master

 

maybe something like:

theChildren.addall(master.children__r)

Mehmet_ErgunMehmet_Ergun
Its an order of execution problem.  By the time the after delete trigger runs, the system has already cleared the child records of the parental lookup association.  So, you can't run operations on children after the delete because you don't know who the children were.  To put it in context, I have built a cascading deletions class that allows multi-level cascading deletions N number of layers deep.  It works fine, but it runs in the before-update context.  I wanted to make it run after update so that I could make the class method asyncrounous.  That way I could increase the SOQL limits.   So the only thing I can think of is to place a trigger on all children records everywhere that copies the parental id to a hidden field every time it changes (unless Nulled of course)... However I don't like it because its cloogy....
I was hoping someone might see something I've missed and there is another way to pick up the deleted parent ids on orphaned children.