繁体   English   中英

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

[英]How do I get info from lookup in salesforce query

I have a custom salesforce object Installation__c and it has a custom field Product__c which is a lookup to a custom object Product__c I am trying to get the fields from the child object using these query:

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但似乎都不起作用,我该如何修复我的查询?

如果您正在向上或向下遍历关系层次结构,则 __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的关系

单击已查找的 object 上的关系。 复制添加__r的关系名称

这个例子是Test_Drives__r

在此处输入图像描述

暂无
暂无

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

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