You need to sign in to do that
Don't have an account?

Trigger on related case to update parent case
Hi all,
I am trying to create a trigger on a related case that would update a field on the parent case when the new related (child) case is created against the parent. I am not an expert at apex triggers but have modified some code. I have copied it below.
Can anybody help me complete the code for this to work.
Thanks
trigger UpdateParentCase on Case (after insert, after update){
Case relcase = Trigger.new[0];
Case ca = new Case();
for(Case c:[Select Id, Attempted_Call__c from Case where
Id = :relcase.Parent limit 1]){
ca = c;
ca.Attempted_Call__c = true;
update ca;
}
}
You are using Trigger.new[0]. This will only update the first Case record that was triggered. I am not sure if you want to do that.
Here is an Example:
All Answers
Hi,
You will have to check if ParentID field is not null. This will assure you that the case which you are creating is a child.
Then fetch the "ParentID" value from the new case and then update the parent case using the "ParentId" value.
Shweta
Salesforce Developer Support
If my answer solved your question, please mark it solved so I can help as many community members as possible!
Thanks for your response. Unfortunately I do not know how to code an apex trigger for that. I have a minimal understanding of this.
can you please show me how the code should look like ?
thanks
You are using Trigger.new[0]. This will only update the first Case record that was triggered. I am not sure if you want to do that.
Here is an Example:
Hi again,
thanks for your response. I had to modify the code slightly after some trial and error and finally got it. here it is below. Thanks for your help on this.
Hi Can you help with the same trigger.
I want to update the status field on parent case when child case status is updated? Is it possible. Can you send me the sample for that?
Thanks
Abi