如何从 salesforce 查询中的查找中获取信息

How do I get info from lookup in salesforce query

我有一个自定义销售团队 object Installation__c,它有一个自定义字段 Product__c,这是对自定义 object Product__c 的查找尝试使用这些查询从 child object 中获取字段:

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__r 和 FROM Product__c__r 但似乎都不起作用,我该如何解决我的查询?

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

这个例子是Test_Drives__r

如果您向上或向下遍历关系层次结构,__c 后缀变为 __r('relationship' 为 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