简体   繁体   English

SOQL,Salesforce-用两个where子句连接两个对象

[英]SOQL, Salesforce - Join Two objects with two where clauses

I have two objects named as 'Opportunity' and 'Account. 我有两个对象,分别称为“机会”和“帐户”。 I need to select ID, OpportunityName,CreatedDate from Opportunity table and AccountName, AccountCat from Account table where Account.OpportunityID = Opportunity.ID and AccountCat = 'DC'. 我需要从“机会”表中选择ID,OpportunityName,CreatedDate和从“账户”表中选择AccountName,AccountCat,其中Account.OpportunityID = Opportunity.ID和AccountCat ='DC'。

I refer this tutorial and executed in workbench , but didn't work. 我参考了教程并在workbench中执行,但是没有用。

Following is the query I used. 以下是我使用的查询。

SELECT AccountName, AccountCat (SELECT Id, OpportunityName,CreatedDate FROM Opportunity) FROM Account WHERE OpportunityID 
IN (SELECT Id FROM Opportunity) AND AccountCat = 'DC'

Run your query on the Opportunity object and then use reference fields to select fields from the parent object. 在商机对象上运行查询,然后使用参考字段从父对象中选择字段。

SELECT  Id
    ,   Name
    ,   CreatedDate
    ,   Account.Name
FROM    Opportunity
WHERE   Account.Name = 'GenePoint'

AccountCat is not a standard field, so I assume it's a custom field, in which case you need to use the developer name, probably something like Account.Cat__c or Account.Category__c or something like that. AccountCat不是一个标准字段,因此我假设它是一个自定义字段,在这种情况下,您需要使用开发人员名称,可能使用诸如Account.Cat__cAccount.Category__c类的名称。

SOQL is superficially similar to SQL, but there are significant differences, one of them being how records are joined. SOQL从表面上看类似于SQL,但是存在显着差异,其中之一是记录的连接方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM