簡體   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