soql通过联结对象获取数据

时间:2013-04-20 15:04:14

标签: salesforce apex-code

我有以下三个自定义对象:

Order__c

Design__c(查找Order和查找Location,因此设计ojbect是联结对象)

Location__c

在订单页面布局上,我想添加一个包含VF页面的空白部分,以显示订单所有设计记录的位置记录。

订单可以有很多设计,设计可以有很多位置。我需要一种方法来分组和显示订单上VF页面中的每个设计/位置。

如何构建此查询并在VF页面上显示结果?

我正在尝试这样的查询:选择Location_ r.Name,位置 _r.Mockup来自Design_ c,其中订单 _c ='xxxxxxxxxxxxxx'

另外,除了相关列表中的VF页面部分之外,还有更好的方法来显示结果吗?

感谢您的帮助!

问候。

1 个答案:

答案 0 :(得分: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.