在 Apex 或 VisualForce 中合并以下两个列表的最佳方法是什么?数据是相关的,但是不能一起查询,所以需要把两个List合并起来。
注意事项:
这两个列表:additionalInfoQuestionMaps 是父列表,additionalInfoQuestionAvailableResponses 是子列表。可以有 1 到多个孩子。
我需要加入 Question_Type_Info__c 对象的列表。
基本上它是一组来自父列表的问题,然后我需要将可能的答案与这些问题相关联,例如位于子列表中的是和否。这些结果将以表格的形式显示在 VF 页面上。
public with sharing class mytest {
public List<Questions__c> additionalInfoQuestionMaps {get;set;}
public List<Available_Question_Answer_Options__c> additionalInfoQuestionAvailableResponses {get;set;}
public List<retrieveMergedQuestionList> retrieveMergedQuestionLists {get;set;}
public String buildId {get;set;}
public Build__c build {get;set;}
public mytest() {
buildId = 'a1DV00000001BBBBBB';
build = sharedfile.getBuild(buildId);
updateAdditionalInfoQuestionMaps();
updateAdditionalInfoFieldValueIds();
updateAdditionalInfoQuestionAvailableResponses();
}
public void updateAdditionalInfoQuestionMaps() {
additionalInfoQuestionMaps = new List<Questions__c>([SELECT Id, Name,
Associated_Product_Item__c,
Associated_Product__c,
Label__c,
(select Response__c from Responses_Object__r),
Question_Type_Info__c,
Required__c
FROM Questions__c
WHERE Associated_Product__c = :build.Associated_Product__c
ORDER BY Sort_Index__c, Label__c]);
}
public Set<Id> additionalInfoFieldValueIds = new Set<Id>();
public void updateAdditionalInfoFieldValueIds(){
for (Questions__c aimb : additionalInfoQuestionMaps) {
additionalInfoFieldValueIds.add(aimb.Question_Type_Info__c);
}
}
public void updateAdditionalInfoQuestionAvailableResponses() {
additionalInfoQuestionAvailableResponses = new List<Available_Question_Answer_Options__c>([select Id,
Field_Value__c, Question_Type_Info__c
from Available_Question_Answer_Options__c
where Question_Type_Info__c IN :additionalInfoFieldValueIds]);
}
}