I have a trigger on an object ('item'), which is a child of 'parent', which is in turn a child of 'grandparent'.
So a SOQL query involving item.parent__r.grandparent__c
normally returns the ID of the related grandparent record.
My problem arises when working with an AfterDelete trigger context, because I can only work with trigger.old.
The record info pulled by the trigger is limited to the object itself, so item.parent__r.grandparent__c
isn't accessible without querying.
But, I can't actually query that grandparent relationship since the record is now deleted:
[SELECT ID, parent__r.grandparent__c FROM Item WHERE ID IN :trigger.Old]
returns nothing, because there ARE no more Item records with that ID, because they are deleted at this point.
My current workaround is to build a list of parent IDs, since those values are included in trigger.old, then to query the grandparent IDs using a query on the parent object.
I'm wondering: is there a better way to get multi-level relationship info in this context?