[英]how to iterate through a list in salesforce
I am new to salesforce, I want to iterate the department images, can anyone help me? 我是Salesforce的新手,我想遍历部门图像,有人可以帮助我吗?
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 有关Force.com
List class
更多示例,您可以在此处查看其文档
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.