+ Start a Discussion

recursively deleting events and tasks below them in hierachy


I have below usecase:
When User deletes a task or event, the tasks and events which are below them in hierarchy or they are linked to should also be deleted

Thanks for suggestions !

Best Answer chosen by Sandrine
Prabhat Kumar12Prabhat Kumar12
You need to write a before delete trigger, before deleting the trigger it will store related task and event to delete.
Look into below sample code.
trigger onParentObjectDelete on CustomObject__c (before delete){
List<Id> idsToQuery = new List<Id>{};
for(CustomObject__c a: Trigger.new){

//query all child records where parent ids were deleted
ChildObject__c[] objsToDelete = [select id from ChildObject__c where ParentId__c IN :idsToQuery];

delete objsToDelete; //perform delete statement