简体   繁体   English

SOQL-如何获取组合附件的父名称

[英]SOQL - How to obtain Parent Name of CombinedAttachments

I am unable to obtain the Name of a Parent object, where the child is CombinedAttachments. 我无法获得父对象的名称,其中子对象为CombinedAttachments。 The SOQL I use is listed below and works as expected. 我使用的SOQL在下面列出,并且可以正常工作。

SELECT ( SELECT Id, Title, RecordType, LastModifiedDate, CreatedBy.Name, ParentId from CombinedAttachments WHERE ParentId = '001b0000009ovxS' ORDER BY LastModifiedDate DESC limit 100 ) FROM Account WHERE Id = '001b0000009ovxS' SELECT(SELECT Id,Title,RecordType,LastModifiedDate,CreatedBy.Name,ParentId from CombinedAttachments WHERE ParentId ='001b0000009ovxS'ORDER BY LastModifiedDate DESC limit 100)FROM Account WHERE Id ='001b0000009ovxS'

What is impossible is to add a filed like Parent.Name or Parent.Account.Name. 添加诸如Parent.Name或Parent.Account.Name之类的文件是不可能的。 However, in other cases of Parent-Child queries like that, it is straightforward to refer to Parent fields by using dot notation like Parent.CaseNumber or Who.Name It seems that due to the fact that there may be multiple references possible in ParentID (Account,Asset,Campaign,Case,Contact,Contract,EmailTemplate,Event,Lead,Opportunity,Product2,Solution,Task) 但是,在诸如此类的“父子”查询的其他情况下,可以通过使用点表示法(例如Parent.CaseNumber或Who.Name)来直接引用“父”字段,这似乎是由于在ParentID中可能存在多个引用(账户,资产,活动,案例,联系人,合同的emailTemplate,事件,铅,机会,产品2,解决方案,任务)

With a polymorphic relationship field, such as CombinedAttachments.ParentId , the field can reference a large number of types. 对于多态关系字段,例如CombinedAttachments.ParentId ,该字段可以引用大量类型。

In this case you can only select a subset of fields that are common to all the types being referenced. 在这种情况下,您只能选择对所有被引用类型都通用的字段子集。

You will need to do secondary queries to Account to pull the required fields. 您将需要对帐户进行辅助查询,以提取必填字段。

Alternatively, you might be able to reverse the join to get the Account fields, but you have now lost the CombinedAttachments fields. 或者,您可能可以反向联接以获取“帐户”字段,但是现在您丢失了CombinedAttachments字段。

SELECT Id, Name
FROM Account
WHERE Id IN (Select ParentID from CombinedAttachments)

As an aside, there is a dedicated Salesforce StackExchange site for Salesforce questions. 顺便说一句,有一个专用的Salesforce StackExchange网站可解决 Salesforce问题。

One tested approach is to use the Parent field name in the parent side rather then refer to it from the sub-query: 一种经过测试的方法是在父侧使用“父”字段名称,而不是从子查询中引用它:

SELECT Name, Id, ( SELECT Id, Title, RecordType, LastModifiedDate, CreatedBy.Name, ParentId from CombinedAttachments WHERE ParentId = '001b0000009ovxS' ORDER BY LastModifiedDate DESC limit 100 ) FROM Account WHERE Id = '001b0000009ovxS' SELECT Name,ID,(SELECT ID,Title,RecordType,LastModifiedDate,CreatedBy.Name,ParentId from CombinedAttachments WHERE ParentId ='001b0000009ovxS'ORDER BY LastModifiedDate DESC limit 100)FROM Account WHERE ID ='001b0000009ovxS'

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

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