1

我尝试对 SalesForce Db 执行左外连接,以从 Product2 表中获取 Id 和 ProductCode 字段,并从关联的(如果存在)PriceBookEntry 中获取一些字段。我也有 ID='01sd00000008iWpAAI' 的 PriceBook2。这是示例查询:

SELECT Id, ProductCode, 
(SELECT Id, PriceBook2Id, PriceBookEntry__r.Product2Id FROM PriceBookEntry__r 
WHERE PriceBook2Id='01sd00000008iWpAAI') 
FROM Product2 WHERE ProductCode IN 
('151','250','256','270','289')

返回给我的错误是:

INVALID_TYPE: PriceBookEntry__r.Product2Id FROM PriceBookEntry 
WHERE PriceBook2Id='01sd00000008iWpAAI') 
^ ERROR at Row:1:Column:89 
Didn't understand relationship 'PriceBookEntry__r' in FROM part of query call. 
If you are attempting to use a custom relationship, 
be sure to append the '__r' after the custom relationship name. 
Please reference your WSDL or the describe call for the appropriate names..

我为此查询尝试了几种变体,但没有成功。我在 Product2 表中有这些 ProductCodes 的行。

我在那里想念什么?

4

1 回答 1

1

我找到了解决方案:关键在 PriceBookEntry 表中。它应该是复数形式(PriceBookEntries)。所以查询应该是:

SELECT Id, ProductCode, 
(SELECT Id, PriceBook2Id, Product2Id FROM PriceBookEntries
WHERE PriceBook2Id='01sd00000008iWpAAI') 
FROM Product2 WHERE ProductCode IN 
('151','250','256','270','289')
于 2012-09-11T20:22:40.070 回答