如何从Salesforce查询中获取信息

时间:2019-10-28 15:47:00

标签: salesforce apex soql

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

2 个答案:

答案 0 :(得分: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

答案 1 :(得分:0)

单击具有查找对象的关系。复制添加了<?xml version="1.0"?> <abc:example xmlns:abc="http://something.different.example.com"> <abc:foo>42</abc:foo> </abc:example> 的关系名称

此示例为__r

enter image description here

相关问题