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
Abhishek chauhan 20Abhishek chauhan 20 

delete child rec when parent rec is delete both having lookup relation parent obj name = Object_1__c && Child obj name Object_2__c field in child obj name = Child_Of__c this field have lookup relation to parent

Sai PraveenSai Praveen (Salesforce Developers) 
Hi Abhishek,

Can you try the below trigger on Object_1__c
 
trigger DeleteChildRecords on Object_1__c (before delete) {
    Set<Id> obj1ids= new Set<Id>();
    For(Object_1__c obj:Trigger.old){
        obj1ids.add(obj.id);
    }
    
    If(obj1ids.size()>0){
        List<Object_2__c > objtobedeleted=[select id,Name from Object_2__c where Child_Of__c in:obj1ids];
        if(objtobedeleted.size()>0)
            delete objtobedeleted;
        
    }

}

Let me know if you face any issues.

If this solution helps, Please mark it as best answer.

Thanks,