Below summarizes the issue I am encountering around Tasks with contacts associated.
Scenario 1: When a contact is removed from an existing task, the removed contact should look up all associated tasks and evaluate MAX ActivityDate value.
Scenario 2: When a task has been deleted with x number of contacts, all x contacts should independently evaluate MAX ActivityDate based on associated tasks to each contact.
Problem: using an AFTER update / delete trigger on Task object, the removed contacts can no longer be seen in the TaskRelation soql query below. TaskRelation cannot have triggers or be referenced in Trigger.old and Trigger.new context as far as I am aware. Also, a Task query only ever returns one record with the WhoId populated with the main contact regardless of how many contacts are associated, the TaskRelation is where the contact associated can be fetched based on below soql.
Query used - returns MAX ActivityDate by contact:
TaskRelation contactTasks = [SELECT Task.ActivityDate
WHERE IsDeleted = false and RelationId = :contactId AND
Task.ActivityDate != NULL
ORDER BY Task.ActivityDate DESC];
Any help / ideas are much appreciated!