You need to sign in to do that
Don't have an account?
MoroY
Reopening child cases
Hello everyone, I am quite new on the platform and have a rather interesting task to solve. I have been playing around with a Trigger but I have not gotten that far. Help is much appreciated.
For Cases:
1. If the parent case is closed, I would like to prevent the child case status from changing from closed to open.
2. A generic error message should be displayed informing the user of this
3. When child case status has been changed from closed to open, the child case cannot be saved if the parent case is not open
4. When child case status has been changed from closed to open, the child case can be saved if parent case also has status of open
For Cases:
1. If the parent case is closed, I would like to prevent the child case status from changing from closed to open.
2. A generic error message should be displayed informing the user of this
3. When child case status has been changed from closed to open, the child case cannot be saved if the parent case is not open
4. When child case status has been changed from closed to open, the child case can be saved if parent case also has status of open
try with beloe validation rule.
If this helps, Please mark it as best answer.
Thanks!!
All Answers
try with beloe validation rule.
If this helps, Please mark it as best answer.
Thanks!!
You can simply create a validation rule to prevent this. There is no need to write a logic in the trigger.
Still, if you are curious how we can do that in trigger then please find the solution
trigger CaseTrigger on Case (before update) {
Set<Id> caseIdSet = new Set<Id>();
List<Case> caseList = new List<Case>();
for (Case cs : Trigger.new) {
if (cs.Status != Trigger.oldMap.get(cs.Id).Status && cs.Status == 'Open' && cs.ParentId != null) {
caseIdSet.add(cs.Id);
caseList.add(cs);
}
}
if (caseIdSet.size() > 0) {
//Either query the same case with parent status or query the parent case. Here I am querying the same case
Map<Id,Case> caseMap = new Map<Id,Case>([SELECT Id, Parent.Status FROM Case WHERE Id IN :caseIdSet]);
for (Case cs : caseList) {
if (caseMap.containsKey(cs.Id) && caseMap.get(cs.Id).Parent.Status == 'Closed') {
cs.addError('You can not open the case as parent case is already closed');
}
}
}
}
Please mark this as the best answer if it helps
Thanks
Shubham Jain
Thank you Shubhaim for taking the time to create the Trigger example.
Although intitially the Child case status is prevented from being saved from Closed to Open if the Parent status is Closed, if I pick a different value for the Child case other that Closed (for example Processing), and then save as Open, it is saved. Even though the Parent status remains Closed.
If yes, then validation rule will not work. it will fire only when change the status from closed to open.
If there any chance to modify the status from closed to other than open then we need to include the remaing conditions in validation rule.
try with below.
If you don't want to change the chail case status when parent case is closed. try with below.
Let me know if any other changes required.
Thanks!!
EX:
AND( ISPICKVAL(Parent.Status,'Closed'),ISCHANGED( Status ), ISPICKVAL(PRIORVALUE(Status),'closed'),
|| ISPICKVAL(PRIORVALUE(Status),'Processing'), ISPICKVAL(Status,'Open') )