+ Start a Discussion
bpolbpol 

"Loop must iterate over a collection type" Error

I am getting the error "Loop must iterate over a collection type: SOBJECT: ROI__c" coming from the second loop in the excerpt below.

 

Not sure how to resolve...

 

 

Set <id> studentListIds = new set <id> ();

for (Student__c aa :studentList) {
     studentListIds.add (aa.id);
}
	
ROI__c roiStudentList = [select Id, Related_Student__c from ROI__c where Related_Student__c in :studentListIds];
		
for(ROI__c xx : roiStudentList) {
     System.assertNotEquals(null, xx.Related_Student__c);
}

 

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
bpolbpol

Needed to replace

 

ROI__c roiStudentList = [select Id, Related_Student__c from ROI__c where Related_Student__c in :studentListIds];

with

 

List <ROI__c> roiStudentList = [select Id, Related_Student__c from ROI__c where Related_Student__c in :studentListIds];

 

All Answers

bpolbpol

Needed to replace

 

ROI__c roiStudentList = [select Id, Related_Student__c from ROI__c where Related_Student__c in :studentListIds];

with

 

List <ROI__c> roiStudentList = [select Id, Related_Student__c from ROI__c where Related_Student__c in :studentListIds];

 

This was selected as the best answer
Angie ShonaAngie Shona
Wow tysm :)