You need to sign in to do that
Don't have an account?
Update field on parent case when any child case is open
I want to restrict user from closing parent case when any of it's child case is open and as well as update a checkbox to true if any child case is open, am able to restrict from closing parent case if child case is open but am not able to update the field to true , am not sure how to modify the trigger to solve both the tasks , any help is appreciated .
trigger PreventParentCaseClose on Case (before update,after update) {
if(Trigger.New[0].Status == Trigger.old[0].Status)
return;
if
(Trigger.New[0].Status=='Closed' || Trigger.New[0].Status=='Declined')
if ([Select count() from Case where ParentId = :Trigger.New[0].id and isClosed != true] > 0)
{
Trigger.New[0].addError('There are still Child Cases Open - Please close them and try again!');
Trigger.New[0].Child_Case_Open__c = true;
}
}
TIA!
Use This code:-
if(Trigger.Old[0].Status == Trigger.new[0].Status)
return;
if
(Trigger.New[0].Status=='Closed' || Trigger.New[0].Status=='Declined')
if ([Select count() from Case where ParentId = :Trigger.New[0].id and isClosed != true] > 0)
{
Trigger.New[0].addError('There are still Child Cases Open - Please close them and try again!');
Trigger.New[0].Child_Case_Open__c = true;
If This is correct then tick the questions
as you are generating a validation u can't peform any DML on the same it will roll back the operation. But why can't you make this checkbox field defaults to true and when ever a parent case is closing check the child cases are closed or not if closed then make this as false.....reverse logic i am taking abt...? hope you got it
Kiran,
Well the point is i want to check if all my child cases are open or closed so without scrolling down the parent case i want this checkbox as an indicator to tell me if anyone of the cases are open , so if a a parent case has 2 child cases then if any one case is open then i want this field to be true,does it makes sense?
ya ur scenario wil work according to the old post.. default is checked any ways u opened a case with some status apart from closed or declined there after the trigger will take cares abt the child record status change check and that check box value based on the stage value
well it's not working , i have one parent case and one child cases , i made the check box to true by default and when i closed the child case still this box is being checked which is wrong because when there are no open child cases this should be false, am i right?