Reputation: 69
I am new to salesforce, I want to iterate the department images, can anyone help me?
Here is the code:
public class Hospital_Controller {
public List<attachment> HodImages {get; set;}
string recid;
string recId1 ;
public Hospital_Controller(ApexPages.StandardController controller) {
recId = controller.getId();
HodImages = new List<attachment>();
List<Department__c> depIds =[select id from Department__c];
HodImages = [select id,name from attachment where parentId =:depIds];
}
}
Upvotes: 2
Views: 30829
Reputation: 1081
You can do two ways to iterate a List in apex.
Here is an advance way to loop on a list.
List<string> stringList = new List<String>{'sample1', 'sample2'};
for (String str : stringList)
system.debug(str);
Or you could do it on usual for loop.
List<string> stringList = new List<String>{'sample1', 'sample2'};
for(Integer i = 0; i < stringList.size(); i++)
system.debug(stringList[i]);
For more example of Force.com List class
you can check their docs here
Upvotes: 5