0

I have a soql query ran in a trigger on AfterDelete of parent that finds all deleted objects that are children of this parent. It looks like this:

SELECT Id, FROM child_object_c where ParentID='123' AND IsDeleted=true ALL ROWS

However, what I really need is to only get the children records that were deleted as a result of a cascade delete from the parent. This query currently includes all deleted children, not just the ones from cascade deletes.

Is there any way to filter the query on whether a record deletion was from a cascade delete?

  • Could you just add Parent.IsDeleted=true? – Bryan Anderson Nov 14 '19 at 19:20
  • Maybe you could create a formula field Checkbox that contains LastModifiedDate == Parent.LastModifiedDate, then use that in the filter? You may have to build in some sort of way to allow a second or so difference (or maybe more). Also, I'm not 100% sure the LastModifiedDate of the child records actually get updated if they're deleted by a cascade. If it's not you could implement a trigger that runs before delete that updates the then existing child records. – rael_kid Nov 14 '19 at 19:23
  • @BryanAnderson I can't use Parent.IsDeleted=true because it is already in the AfterDelete trigger. @rael_kid, I don't think the LastModified or the SystemModStamp are updated on cascade deletes.... at least not while in the trigger context. – Elliot Nov 14 '19 at 19:25
  • 2
    If you're in the after delete trigger context you might be able to move your logic to the before delete trigger and use the existing (non-deleted) child records. – rael_kid Nov 14 '19 at 19:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.