0

I have the following select statement, but it giving me errors. When I query separately it works. I tried under query editor also. Same error.

List<Deposit_Detail__c> depositDetailList = [Select Deposit__r.Name,  Id,Amount__c, Member_Name__c from Deposit_Detail__c Where Id IN :trigger.new];

The error is as follows:

Select Deposit__r.Name, Id,Amount__c ^ ERROR at Row:1:Column:8 Didn't understand relationship 'Deposit__r' in field path. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name.

Note that its nothing to do with trigger.new. I removed the trigger.new from the select entry. still has error. The same way I did it in other triigers/classes and its works. The following code works as an example:

List<Receipts_Payments__c> memberList = [Select Member__r.Id, Member__r.Name, Member__r.Email__c, 
        Id, Member__c, RecordTypeId from Receipts_Payments__c where Id IN :trigger.new
        ];

But this one doesn't.

List<Deposit_Detail__c> depositDetailList = [Select Deposit__r.Name,  Id,Amount__c, Member_Name__c from Deposit_Detail__c Where Id IN :trigger.new]; 

I even tried to use child to parent relationship query, that doesn't too.

Parent object API name : Deposit__c
Child Object API Name: Deposit_Detail__c
Child Relationship Name : Deposit_Details

I don't know whether the error is related to object itself.

2
  • 2
    what's the actual API field name of the lookup/master-detail of Deposit__c on the Deposit_Detail__c object. Commented Jan 15, 2021 at 21:08
  • Most likely it is deposits__r
    – Eric
    Commented Jan 16, 2021 at 7:06

1 Answer 1

0

Please make sure to use the lookup field with the extension __r in order to access the parent Object's fields as below:

If the lookup field API name instead of using the parent Object name in the SOQL query.If both are different then this error occurs.

Thank you!

1
  • Thanks. It works Commented Jan 18, 2021 at 7:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .