You need to sign in to do that
Don't have an account?
getting error:Loop variable must be of type SObject at line 9 column 16
public class UpdateTask{ public static Boolean stopDup = false;
public void insertRootCause(List<Task__c> lstTask)
{
set<Id> Ids=new set<Id>();
map<id,id> mapparent=new map<id,id>();
//for(Task__c tsk:trigger.new)
{ //ids.add(tsk.Project__c);}
for(project__c prj: trigger.new) // getting error here..please help as why this error is comimg..I'm trying to get parent's field value here which will be paste in the child of this object
{
mapParent.put(prj.id, prj.Dev_Lead_User__c);
}
if(!stopDup){
List<Root_cause__c> lstRC=new List<Root_Cause__c>();
for(Task__c t:lstTask){
// Project__c project = prj.get(t.project__c);
Root_Cause__c RCDel= new Root_Cause__c();
System.debug('Im Inside 123----->'+t);
RCDel.TaskName__c=t.Id;
system.debug(t.TQL_Phase__c=='6.Launch');
RCDel.Date__c=System.Today();
RCDel.Launch_Date_Delay__c=0;
RCDel.Task_Delay__c=0;
RCDel.Dev_Lead__c= mapParent.get(t.Project__c);
lstRC.add(RCDel);
}
if(lstRC.size()>0){
insert lstRC;
stopDup = true;
}
}
}
}
You can't use trigger.new as you aren't in a trigger, you are in an instance of a class.
If this method is being called from a trigger you'll need to pass trigger.new as a parameter to the method.
thanks for the reply..i have modified my code and it looks something like this now..
public class UpdateTask{
public static Boolean stopDup = false;
public void insertRootCause(List<Task__c> lstTask){
List<project__c> lstprj=new List<project__C>();
set<Id> Ids=new set<Id>();
map<id,id> mapparent=new map<id,id>();
for(Task__c tsk:lsttask){
ids.add(tsk.Project__c);}
lstprj=[select id,Dev_Lead_User__c from project__c where id in :Ids];
map<Id,Project__c> map1=new map<id,project__c>();
for(Task__c t:lsttask){
mapparent.put(t.project__c,t.id);}
for(project__c prj:lstprj){
map1.put(prj.id,prj);
}
if(!stopDup){
List<Root_cause__c> lstRC=new List<Root_Cause__c>();
for(Task__c t:lstTask){
// Project__c project = prj.get(t.project__c);
Root_Cause__c RCDel= new Root_Cause__c();
System.debug('Im Inside 123----->'+t);
RCDel.TaskName__c=t.Id;
system.debug(t.TQL_Phase__c=='6.Launch');
RCDel.Date__c=System.Today();
RCDel.Launch_Date_Delay__c=0;
system.debug(RcDEl.Launch_Date_Delay__c==0);
RCDel.Task_Delay__c=0;
RCDel.Dev_Lead__c= map1.get(mapparent.get(t.id)).Dev_Lead_user__c;
lstRC.add(RCDel);
}
if(lstRC.size()>0){
insert lstRC;
stopDup = true;
}
}
}
}