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];
}
}
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.