SOQL 查询遍历任务上的多个级别

发布于 2024-09-13 18:51:04 字数 284 浏览 8 评论 0原文

我正在尝试使用此查询编写一些顶点代码,但没有得到任何结果:

List<Task> tasks = [SELECT id, whatid, who.account.parent.name FROM task WHERE who.account.parent.name LIKE 'Procter%'];

我并不惊讶这不起作用,但似乎无法在任何地方找到解释我将如何处理此问题的文档。有人知道吗?我正在尝试获取链接到某个联系人的所有任务,该联系人链接到父帐户为“宝洁”的帐户...

I'm trying to write some apex code using this query and not getting anywhere:

List<Task> tasks = [SELECT id, whatid, who.account.parent.name FROM task WHERE who.account.parent.name LIKE 'Procter%'];

I'm not surprised this doesn't work, but can't seem to find documentation anywhere that explains how I would go about this. Does anyone have any idea? I'm trying to get all tasks linked to a contact linked to an account with a parent account of "procter and gamble"...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

手心的温暖 2024-09-20 18:51:04

看起来混合字段中“向上”的选项(查找转到多个对象的选项,例如 WhatId 转到帐户或机会)非常有限。我可以写“WHERE What.name LIKE 'Procter%'”,但不能写“WHERE What.parent.name LIKE 'Procter%'”。

顺便说一句,我认为应该是 WhatId 而不是 WhoId(查看验证规则)任务编辑器,尝试插入字段“联系人/潜在客户 ID”和“机会/帐户 ID”)。这些字段,而对于其他一些字段,您可以探索像“CreatedBy.UserRole.Name”这样的关系,

您可以尝试这个子查询吗?

[SELECT id, whatid FROM task WHERE whatid IN (SELECT Id FROM Account WHERE Parent.Name LIKE 'United%')]

Looks like the options to "go up" in the mixed fields (the ones where Lookup goes to multiple objects like WhatId going to Account or Opportunity) are very limited. I was able to write "WHERE what.name LIKE 'Procter%' but not "WHERE what.parent.name LIKE 'Procter%'".

By the way I think it should be WhatId and not the WhoId (check out the Validation Rule editor for Tasks, try to insert fields "Contact/Lead ID" and "Opportunity/Account ID"). You will also see that you can't "go up" (or in case of this editor - "go right") on these fields while for some other fields you can explore the relation like for "CreatedBy.UserRole.Name".

Can you try this subquery instead?

[SELECT id, whatid FROM task WHERE whatid IN (SELECT Id FROM Account WHERE Parent.Name LIKE 'United%')]
笨死的猪 2024-09-20 18:51:04

WhatId和WhoID是多态字段,因此这些字段不支持遍历多级。

WhatId and WhoID are polymorphic fields, so these fields do not support traversing multiple levels.

末蓝 2024-09-20 18:51:04

我对层次结构遍历有类似的要求,在我的例子中,我必须选择与任务相关的引导信息。我要做的就是首先查询任务列表,然后查询基于这些任务的潜在客户列表,然后使用包装器类将两个列表组合成自定义对象,并使用 Visualforce 相应地显示该对象。包装类当然是我对等式的答案,因为看起来您实际上无法直接使用 Who.Id 进行查询。

希望这有帮助!

I had a similar requirement for hierarchal traversing, in my case i had to select the lead information associated with a task. What I had to do was first query for a list of tasks, then query for a list of leads based off those tasks, then use a wrapper class to combine the two lists into a custom object and display the object accordingly using visualforce. The wrapper class was certainly my answer to the equation since it seems you are in fact unable to query directly using the Who.Id.

Hope this helps!

心碎无痕… 2024-09-20 18:51:04

任务上的 AccountID 字段由 SF 自动为联系人填充。显然,Leads 为空。因此,如果您想获取帐户数据,您可以执行以下操作:

SELECT ID, Who.FirstName, Who.LastName, Account.Parent.Name FROM Task WHERE WhoID = '00Q12SDFUUALDLKJF'

显然,Account.Parent.Name 为空对于潜在客户。

The AccountID field on Tasks is populated by SF automatically for Contacts. Obviously, it is blank for Leads. So, if you want to get Account data you can just do something like this:

SELECT ID, Who.FirstName, Who.LastName, Account.Parent.Name FROM Task WHERE WhoID = '00Q12SDFUUALDLKJF'

Obviously, Account.Parent.Name is blank for Leads.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文