You need to sign in to do that
Don't have an account?
Shubham Sinha 43
Write a trigger to update parent record from child record
I need to update parent record from child record. So, I have four objects- Case, WorkOrder, ServiceAppointmen, ServiceReport. I need to write a trigger when ServiceReport record is created then field (Test__c) of Case object should be checked. Case is parent object of Workorder, Workorder is parent Object of ServiceAppointment, ServiceAppointment is Parent object of Service report. I have written a trigger and able to upate the field of ServiceAppointment when service report is created but I need to update the field of case .So, I am unable to fetch the Case record's detail from my triggger and do the updation.
trigger :-
trigger :-
trigger sendEmail on ServiceReport (After insert) { list<Id> SerApp = new list<id>(); for(ServiceReport sr : trigger.new){ SerApp.add(sr.Parentid); } list<ServiceAppointment> sa = [SELECT id,Report_Generated__c from ServiceAppointment WHERE id in: SerApp]; for(ServiceAppointment a : sa){ a.Report_Generated__c = true; } update sa; }
I have gone through your question. To update the record of the case first you have a query each parent object one by one.
Please try the code given below:-
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha
www.kdeepali.com
All Answers
You can refer below code. Please check the fields API names, as there might be some differences, as my org is not FSL enabled:
I have gone through your question. To update the record of the case first you have a query each parent object one by one.
Please try the code given below:-
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha
www.kdeepali.com