【问题标题】:How do I get info from lookup in salesforce query如何从 salesforce 查询中的查找中获取信息
【发布时间】:2019-10-28 15:47:00
【问题描述】:

我有一个自定义 salesforce 对象 Installation__c,它有一个自定义字段 Product__c,它是一个自定义对象 Product__c 的查找我正在尝试使用这些查询从子对象中获取字段:

public with sharing class InstallationController {
    @AuraEnabled
    public static List<Installation__c> getItems() {
        // Perform isAccessible() checking first, then
        return [SELECT Id, Name, Installation_Display_Name__c, Product__c, Status__c, (SELECT Product__c.Name FROM Product__c)  FROM Installation__c];
    }
}

我得到错误:

Didn't understand relationship 'Product__c' 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.

我尝试将查询更改为 FROM Product__rand FROM Product__c__r 但似乎都不起作用,我该如何修复我的查询?

【问题讨论】:

  • 您需要转到包含查找的对象,并在单击后使用 __r 复制 Child Relationship name 名称。

标签: salesforce apex soql


【解决方案1】:

如果您要向上或向下遍历关系层次结构,则 __c 后缀将变为 __r(r 表示“关系”),直到您最终到达您要查找的字段(如果它是自定义字段,则仍以 __c 结尾场地)。所以在你的情况下,它会是

public with sharing class InstallationController {
    @AuraEnabled
    public static List<Installation__c> getItems() {
        // Perform isAccessible() checking first, then
        return [SELECT Id, Name, Installation_Display_Name__c, Product__r.Name, Status__c FROM Installation__c];
    }
}

所以,这里的变化是,对于你必须使用 Product__r.Name

的关系

【讨论】:

    【解决方案2】:

    点击进入有查找对象的关系。复制添加__r的关系名称

    这个例子是Test_Drives__r

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-02-03
      • 2016-12-24
      • 1970-01-01
      • 1970-01-01
      • 2022-11-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多