You need to sign in to do that
Don't have an account?
Rustin Fincke
Update parent record status when all children status closed
Hey all,
I've been looking for a solution to this and cannot seem to find anything to accomplish what I am trying to do. I'm trying to update a Parent in the Case object and change the status to Completed only after all child cases and related cases have been closed. (We use a record type called Master Case in the case Object and create addtional case record types for various tasks for different teams. These tasks can include other cases in the case object or other Custom Objects)
We're trying to update the Parent case status when all the related cases and objects are completed.
I found the following code but we're not using the milestone feature at this time: https://developer.salesforce.com/forums/?id=906F0000000As65IAC
I've been looking for a solution to this and cannot seem to find anything to accomplish what I am trying to do. I'm trying to update a Parent in the Case object and change the status to Completed only after all child cases and related cases have been closed. (We use a record type called Master Case in the case Object and create addtional case record types for various tasks for different teams. These tasks can include other cases in the case object or other Custom Objects)
We're trying to update the Parent case status when all the related cases and objects are completed.
I found the following code but we're not using the milestone feature at this time: https://developer.salesforce.com/forums/?id=906F0000000As65IAC
Please see a similart code which updates parent's records when the child records are closed.
Please let me know if it helps
Best Regards
Naga kiran
All Answers
Please see a similart code which updates parent's records when the child records are closed.
Please let me know if it helps
Best Regards
Naga kiran
It will work, if all child object records status is set to 'closed', parent object we can set as closed.
Trigger ChildObjTrigger on childObj(after insert,after update){
List<ParentObj> ParentObjList = new List<ParentObj>();
List<ParentObj> ParentObjListToUpdate = new List<ParentObj>();
Set<Id> parentId = new set<Id>();
for(childObj child : Trigger.new){
if(child.Status == 'Closed'){
parentId.add(child.parentObj);
}
}
if(parentId.size() > 0)
{
ParentObjList = [SELECT Id,Status,(SELECT Id,Status
FROM childObj__r) FROM ParentObj WHERE Id IN : parentId];
for(ParentObj po : ParentObjList){
Boolean setToClosed = true;
for(childObj co : po.childObj__r){
//put condtion which all status you dont want to set Closed
//any other conditions also we can check
if(co.Status == 'Open' || co.Status == 'Canceled'|| co.Status == 'Completed'){
setToClosed = False;
break;
}
}
if(setToClosed){
po.Status = 'Closed';
}
ParentObjListToUpdate.add(c);
}
}
if(!ParentObjListToUpdate.isEmpty() || ParentObjListToUpdate.size() > 0){
update ParentObjListToUpdate;
}
}
Thanks,
Santosh K