2012-05-24 81 views
2

在Apex或VisualForce中合併下面兩個列表的最佳方式是什麼?數據是相關的,但不能一起查詢,所以我需要組合這兩個列表。如何合併Apex或VisualForce(Salesforce)中的兩個列表中的數據?

注意事項:

  1. 兩個列表:在additionalInfoQuestionMaps是父表和additionalInfoQuestionAvailableResponses是孩子。可以有一對多的孩子。

  2. 我需要加入Question_Type_Info__c對象上的列表。

基本上它的一組從父親列表未來問題的,那麼我就需要能夠回答這些問題,比如是關聯和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]); 

    }   

} 
+0

您的問題很難讓我跟隨。你能指定你想合併到一個列表中的哪兩個列表(請給出確切的變量名稱)? –

回答

相關問題