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

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 Ab
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:{

//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