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
Linga_RaminLinga_Ramin 

Can anyone help me out with this scenario on Case Object.This is Urgernt.I have one scenario regarding 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,

I think this can be handled using a trigger with context variables that gets evaluated to true as per the use case, below is one of the example I found in the link [ https://developer.salesforce.com/forums/?id=9060G0000005ResQAE ] that you could use for your 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());
    }
}

I hope this comes handy.

Regards,
Anutej