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

如何从salesforce查询中的查找中获取信息,salesforce,apex,soql,Salesforce,Apex,Soql,我有一个自定义salesforce对象安装,它有一个自定义字段Product,这是一个自定义对象Product的查找。我正在尝试使用以下查询从子对象获取字段: public with sharing class InstallationController { @AuraEnabled public static List<Installation__c> getItems() { // Perform isAccessible() checking

我有一个自定义salesforce对象安装,它有一个自定义字段Product,这是一个自定义对象Product的查找。我正在尝试使用以下查询从子对象获取字段:

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];
    }
}
我已尝试将查询更改为
从Product\u rand到Product\u c\r,但两者似乎都不起作用,如何修复我的查询?

单击具有查找功能的对象上的关系。复制关系名称并将_\r添加到其中

这个例子就是测试驱动器


如果要向上或向下遍历关系层次结构,_c后缀将变为“relationship”的_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\u r.Name

您需要转到包含查找的对象,并在用u\r after单击它之后复制子关系名称。
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];
    }
}