2013-04-20 80 views
2

我有以下三個自定義對象:SOQL通過結對象獲取數據

Order__c

Design__c(有一個查找訂購和查找到的位置,這樣的設計ojbect是結對象)

Location__c

在訂單頁面佈局我想添加一個空白部分,包含以對所有的設計記錄的順序顯示的位置記錄的VF頁。

訂單可以有許多設計,並且設計可以有多個位置。我需要一種方法在訂單上的VF頁面中對每個設計/位置進行分組和顯示。

如何構建此查詢並在VF頁面上顯示結果?

我是想這樣的查詢:選擇位置指定:r.Name,位置 _r.Mockup從Design_ c其中訂單 _c =「XXXXXXXXXXXXXX」

此外,有沒有更好的方式來顯示結果除了相關列表中的VF頁面部分?

感謝您的幫助!

問候。

回答

1

第一件事,第一件事。由於設計通過查找與其他2個對象相關,因此它不是聯接對象。聯結對象只有在2個父母與孩子有主 - 細節關係時纔是。

我想你試圖實現的是遍歷父母 - 子女 - 父母關係。你需要在最後一半使用子查詢。從文檔 - 這裏你去:http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_soql_relationships.htm

Query **child-to-parent relationships**, which are often many-to-one. Specify these relationships directly in the SELECT, FROM, or WHERE clauses using the dot (.) operator. 
For example: 
SELECT Id, Name, Account.Name 
FROM Contact 
WHERE Account.Industry = 'media' 
This query returns the ID and name for only the contacts whose related account industry is media, and for each contact returned, the account name. 




Query **parent-to-child**, which are almost always one-to-many. Specify these relationships using a subquery (enclosed in parentheses), where the initial member of the FROM clause in the subquery is related to the initial member of the outer query FROM clause. Note that for subqueries, you should specify the plural name of the object as that is the name of the relationship for each object. 
For example: 
SELECT Name, 
    (
    SELECT LastName 
    FROM Contacts 
) 
FROM Account 
The query returns the name for all the accounts, and for each account, the last name of each contact.