繁体   English   中英

如何遍历salesforce中的列表

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM