You need to sign in to do that
Don't have an account?
Surender Giri
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.
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;
}
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;
}
I think you can check before update and then in case if there are any child cases which are not in close status you can add an error to that case record, can you try checking if the below code once:
I hope this helps and in case if this comes in handy can you please choose this as the best answer so that it can be used by others in the future.
Regards,
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.
P.S: Just added the code to block for better clarity