SOQL 帐户查询与机会相关的自定义对象

SOQL Account query for custom object related to opportunities

我正在尝试了解如何查询与商机相关的自定义对象。

对象名称是McaApp__Offer__c 该对象的查找字段是 McaApp__Opportunity__c(主从)

这就是我所拥有的,但是我缺少一些东西,因为这个对象与帐户无关,我需要更改什么?

SELECT id, Name, 
  ( 
    Select Id, Name From Opportunities ORDER BY Id DESC LIMIT 1 
  ), 
  ( 
    SELECT McaApp__Funder__c, McaApp__Status__c FROM McaApp__Offers__r WHERE McaApp__Opportunity__c = 'oppidxxx' 
  )   
FROM Account 
WHERE id = 'acctidxxx'

您不能从 Account 中查询 McaApp__Offer__c,因为没有直接关系。 Account < Opportunity < McaApp__Offer__c 事实是这样的。

SOQL statements cannot query aggregate relationships more than 1 level away from the root entity object.

你可以这样做。

SELECT Id, Name, AccountId, 
     (SELECT McaApp__Funder__c, McaApp__Status__c 
     FROM McaApp__Offers__r) 
FROM Opportunity 
WHERE AccountId = 'acctidxxx'
LIMIT 1