Skip to main content
Hi All,

A parent case should be closed only if all its child cases are closed. Parent case shouldn’t be allowed to be closed by the user. Once the last Child case is closed, the Parent Case should automatically be closed.

I written below trigger but is is working if any child case is closed then parent case is automatically closing instead of to close all the child case.

trigger CloseParentCaseTrigger on Case (after update) {

    list<id>idList=new list<id>();

    for(case c:Trigger.New){

        idList.add(c.parentId);

    }

    list<case>csList=new list<case>();

    List<case>caseList=[select id,status,(select id,status from cases) from case where id=:idList];

    system.debug('$$$$caseList: '+ caseList);

    try{

        for(case c:caseList){

            for(case c1:c.cases){

                if(c1.status=='closed'){

                    c.status='closed';

                    csList.add(c);

                    

                }

            }

        }

    }

    catch(exception e){

    }

    update csList;

}
3 answers
  1. Oct 2, 2020, 12:47 PM
    Thanks ANUTEJ ,

    But i don't want to delete or display any error message because our requirement is if all child have case status then parent should also update with close status.
0/9000