Reply
Regular Contributor
Irish@acc
Posts: 60
0

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;    

}    

  }  

   }  

         

  }

Moderator
bob_buzzard
Posts: 6,427
0

Re: getting error:Loop variable must be of type SObject at line 9 column 16

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.

--
Certified Salesforce Technical Architect, Developer, Advanced Developer, Administrator, Advanced Administrator, Consultant, Sales Cloud Consultant,Service Cloud Consultant
Force.com MVP | The Bob Buzzard Blog | Linked In | Twitter

I don't respond to private messages/emails asking for help.


Take the Bob Buzzard Sobject Fields quiz.

Regular Contributor
Irish@acc
Posts: 60
0

Re: getting error:Loop variable must be of type SObject at line 9 column 16

Hi bob
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;
}
}
}


}
Regular Contributor
Irish@acc
Posts: 60
0

Re: getting error:Loop variable must be of type SObject at line 9 column 16

I'm trying to pull out the grand parent field's value and assigning it to grand child object..but gettign an error saying attempt to derefnce null object..plz help
Moderator
bob_buzzard
Posts: 6,427
0

Re: getting error:Loop variable must be of type SObject at line 9 column 16

Where is the null pointer exception - the stack trace should have given you a line number.
--
Certified Salesforce Technical Architect, Developer, Advanced Developer, Administrator, Advanced Administrator, Consultant, Sales Cloud Consultant,Service Cloud Consultant
Force.com MVP | The Bob Buzzard Blog | Linked In | Twitter

I don't respond to private messages/emails asking for help.


Take the Bob Buzzard Sobject Fields quiz.