[英]how to iterate through a list in salesforce
我是Salesforce的新手,我想遍歷部門圖像,有人可以幫助我嗎?
這是代碼:
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];
}
}
您可以通過兩種方法在頂點中迭代列表。
這是在列表上循環的一種高級方法。
List<string> stringList = new List<String>{'sample1', 'sample2'};
for (String str : stringList)
system.debug(str);
或者,您也可以按常規進行循環。
List<string> stringList = new List<String>{'sample1', 'sample2'};
for(Integer i = 0; i < stringList.size(); i++)
system.debug(stringList[i]);
有關Force.com List class
更多示例,您可以在此處查看其文檔
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.