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

Trigger to update grand child
Hi, I have written a trigger to update the grandchild whenevr the field in grand parent object updated..this trigger is however not updating the field ..please help me on this
trigger updateDev_Lead on Project__c(after update)
{
for(project__c prj: trigger.new)
{
if(trigger.oldmap.get(prj.Id).Dev_Lead_User__c!=trigger.newmap.get(prj.Id).Dev_Lead_User__c)
{
List<Task__c> Lsttask=new List<Task__c>();
Lsttask=[Select id,project__c from Task__c where project__c=: prj.Id];
for(Task__c thistask: Lsttask)
{
List<Root_Cause__c> lstRc=new List<Root_cause__c>();
lstRc=[select id,Dev_Lead__c from Root_Cause__c where id =:thistask.id];
List<Root_cause__c> RcToupdate=new List<Root_cause__c>();
for(Root_cause__c thisRc:lstRc)
{
thisRc.Dev_lead__c=prj.Dev_Lead_User__c;
RcToupdate.add(thisRc);
}
if(!RcToupdate.isempty()){
update RcToupdate;
}
}
}
}
}
In this section:
you are selecting the root causes whose ID matches the task id - this is guaranteed to return no rows as no root causes will have that Id. You should be checking the related task id. Something like:
This assumes the id of the related task is stored in the Task_Id__c field - if its a different name, substitute that here.
All Answers
In this section:
you are selecting the root causes whose ID matches the task id - this is guaranteed to return no rows as no root causes will have that Id. You should be checking the related task id. Something like:
This assumes the id of the related task is stored in the Task_Id__c field - if its a different name, substitute that here.