[英]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的關系
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.