You need to sign in to do that
Don't have an account?
Carrie Farnsworth
Trigger to update a field on child of a child
Hi All,
I'm trying to create a trigger (or use workflow rules) to update fields on the child record of a child record and I'm not sure how to do it (if it's even possible).
The parent object is called Project__c. Project__c is the parent to multiple Phase__c records which are parent to multiple Task__c records. When the Project_Status__c field on Project__c is set to cancelled, all associated Task__c records (under the associated Phase__c records) should be have the checkbox field IsCompleted__c set to TRUE and N_A__c checkbox set to TRUE. Does anyone know how I can do this?
I'm trying to create a trigger (or use workflow rules) to update fields on the child record of a child record and I'm not sure how to do it (if it's even possible).
The parent object is called Project__c. Project__c is the parent to multiple Phase__c records which are parent to multiple Task__c records. When the Project_Status__c field on Project__c is set to cancelled, all associated Task__c records (under the associated Phase__c records) should be have the checkbox field IsCompleted__c set to TRUE and N_A__c checkbox set to TRUE. Does anyone know how I can do this?
Use following code
Thanks,
Amritesh
All Answers
You could try something like this on an after update trigger.
if(trigger.new[0].Project_Status__c == 'cancelled' && trigger.new[0].Project_Status__c <> trigger.old[0].Project_Status__c){
try{
list<Task__c> tl = new list<Task__c>();
for(Task__c t: [Select IsCompleted__c from Task__c where Phase__r.Project__c =: trigger.new[0].Id)]{
t.IsCompleted__c = true;
tl.add(t);
}
if(tl != null){
update tl;
}
}catch(exception e){
// no child of child records found
}
}
Use following code
Thanks,
Amritesh