3

So I have these 3 queries, and all of them throw an error about the relationship not being recognized.

this.lineItems = [SELECT QuoteLineItems.Product2Id FROM Quote WHERE Id = :activeQuote.Id];
[SELECT Products__r.Id FROM Product_Hierarchy__c LIMIT 1];
[SELECT Hierarchy_Parent__r.Id FROM Product_Hierarchy__c LIMIT 1];

Technically, I only need the first line in my code, but I put the other two lines for my own testing purposes for this error.

These lines give the following errors and won't allow me to save to the server:

Save error: SELECT Hierarchy_Parent__r.Id FROM Product_Hierarchy__c

ERROR at Row:1:Column:8
Didn't understand relationship 'Hierarchy_Parent__r' in field path. 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.

Save error: SELECT Products__r.Id FROM Product_Hierarchy__c

ERROR at Row:1:Column:8
Didn't understand relationship 'Products__r' in field path. 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.

Save error: SELECT QuoteLineItems.Product2Id FROM Quote

ERROR at Row:1:Column:8
Didn't understand relationship 'QuoteLineItems' in field path. 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.

These are the relevant relationships in the schema:

The child relationships for Product_Hierarchy__c

The child relationship for Quote

Something seems wrong, and I can't figure out what it is.

2 Answers 2

4

Child relationships always use a sub-select:

this.quoteRecord = [SELECT (SELECT Product2Id FROM QuoteLineItems) FROM Quote WHERE Id = :activeQuote.Id];

If you want to query the children directly, use the child object:

this.lineItems = [SELECT Product2Id FROM QuoteLineItem WHERE QuoteId = :activeQuote.Id];
0

I think you want to query the child records of Parent, for that you need to use sub-query

Select Id,(Select Id from QuoteLineItems) from Quote

Like this you need to do other query.

1
  • This answer is basically a duplicate of the existing.
    – Adrian Larson
    Oct 23, 2017 at 17:30

You must log in to answer this question.

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