2014-09-06 63 views
1

Salesforce新手。 我用下面的查詢:Soql:需要幫助訪問數據表中的子查詢值

select name,(select Due_Amount__c from Dues__r where year__c=1990 and month__c=3) from contact where Accountid = '00190000012j4Xi' 

即給予結果作爲

名稱Due__c 羅斯·岡薩雷斯Due_Amount__c
1 400.0 肖恩·福布斯Due_Amount__c 1 300.0

我填充結果在數據表中作爲contact.name:

totalDues = new List<Contact>([select name,(select Due_Amount__c from Dues__r where year__c=1990 and month__c=3) from contact where Accountid =: selectedSoc]); 
     totalDuesWrapperList = new List<contactWrapper>(); 
     for(Contact c : totalDues) 
     totalDuesWrapperList.add(new contactWrapper(c)); 

/*Wrapper class*/ 
public Contact con{get; set;} 
     public Boolean selected {get;set;} 
//  public Due__c totalDues{get;set;} 
     public Due__c dueObj{get;set;} 
     public Decimal totalDues{get;set;} 
     public contactWrapper(Contact c) 
     { 
      con= c; 
      selected = false; 
      totalDues = 0; 
      dueObj = new Due__c(); 
     } 
    } 

視覺力代碼:

<apex:dataTable value="{!totalDuesWrapperList}" var="con" id="contactTable2" columnswidth="50px,50px" cellpadding="4" border="1" title="table2"> 
<apex:column headervalue="Member Name" value="{!con.con.name}" /> 
<apex:column headervalue="Dues Remaining" value="{!con.Due_Amount__c}" /> 
</apex:dataTable> 

的問題是我無法訪問由於量con.Due_Amount__c因爲我已經做了名稱(con.name)

莫非任何人都可以在這方面幫助我。

回答

0

子查詢將自己顯示爲一個集合,因此您需要訪問集合中的單個記錄以獲取值。

E.g.獲得第一筆到期應付金額。

<apex:column headervalue="Dues Remaining" value="{!con.Dues__r[0].Due_Amount__c}" /> 

或者,您可能會發現修改包裝類以將所需值作爲屬性公開是很容易的。

public Decimal DueAmount { 
    get { 
     return con.Dues__r[0].Due_Amount__c; 
    } 
} 

參見:

順便說一句,Salesforce StackExchange是Salesforce的具體問題的好地方。

+0

感謝Daniel的幫助和建議! – 2014-09-10 15:40:44