+ Start a Discussion
Linga_RaminLinga_Ramin 

Regarding Case Object.Scenario on Case and Parent Case.

a.when a case is created for a parent case the update the fields ""TotalChildCases"",""OpenChildcases"" in the parent case b.when a child case is updated to working from open or closed from working the the fields ""ClosedChildcases"",WorkingChildcases"" must get updated c.when a child case is deleted then handle the counts of all the fields in parent case d.when all the child cases are closed then the parent case should be automatically closed e.when the parent case updated to closed without closing the child cases then it should show an error
ANUTEJANUTEJ (Salesforce Developers) 
Hi Linga,

As mentioned in other question you have stated you could use trigger with context variables for this use case and below is an example for reference.
 
Trigger Product2RecordCount on Product2(After Insert, After Update, After Delete, After UnDelete){
    
    List<ID> locationIds = New List<ID>();
    
    If(Trigger.IsInsert || Trigger.IsUpdate || Trigger.IsUnDelete){
        For(Product2 c: Trigger.New){
            if(c.Location__c  != null){
                locationIds.add(c.Location__c);
            }  
        }
    }
    If(Trigger.IsDelete){
        For(Product2 c: Trigger.Old){
            locationIds.add(c.Location__c);
        }
    }
     
    List<Location__c> LocationListToUPdate = New List<Location__c>();
     
    For(Location__c lct: [Select Current_Lot_Inventory__c, (Select ID FROM Products__r) FROM Location__c WHERE ID = :locationIds]){
		lct.Current_Lot_Inventory__c= lct.Products__r.size();
		LocationListToUPdate.add(lct);
    }
     
     
    try{
        Update LocationListToUPdate;
    }
     Catch(Exception E){
        System.Debug('Error Message: ' + e.getMessage());
    }
}

Additionally, I would suggest you to post only one question as it would help us keep the community clean, I hope this helps.

Regards,
Anutej