如何合并Apex或VisualForce(Salesforce)中两个列表的数据?

时间:2012-05-24 17:47:54

标签: salesforce apex-code visualforce

在Apex或VisualForce中合并以下两个列表的最佳方法是什么?数据是相关的,但无法一起查询,因此我需要将两个列表组合在一起。

注意事项:

  1. 两个列表:additionalInfoQuestionMaps是父List,additionalInfoQuestionAvailableResponses是子列表。可以有1到多个孩子。

  2. 我需要在Question_Type_Info__c对象上加入列表。

  3. 基本上它是来自父列表的一组问题,然后我需要将可能的答案与诸如Yes和Nothat之类的问题关联在子列表中。这些结果将以表格形式显示在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]);
    
        }           
    
    }
    

1 个答案:

答案 0 :(得分:0)

如果我理解你的问题,我认为你应该参加一个包装课

看一下我之前在LaceySnr提供解决方案时发布的类似问题

how to create sections of grouped data in Vf page

希望这有帮助。

由于