0
votes

I have a custom object called 'Billings'. On that object there is a custom lookup field to the Opportunity. I'm trying to query all the 'Billings' records associated with a particular Opportunity. I get "Unknown error parsing query".

SELECT Id, StageName, ( SELECT Name, Email FROM Billings__C ) FROM Opportunity WHERE Opportunity ID = '0011000002mfTil'

1

1 Answers

1
votes

For Nested Queries in SOQL, you need to use the '__r' suffix on the Child Relationship Name for the field that provides the look-up from the Child Record to the Parent.

In your case, this is most likely 'Billings__r'. However, to confirm, go to the Billings object and click on the custom field that provides the lookup to the Opportunity object. In the "Lookup Options" section on the Custom Field details screen you will see the official Child Relationship Name without the '__r' suffix. This is the correct name for this relationship for a Nested Query.

The other error in your query is that you have "WHERE Opportunity Id =". It should just be "WHERE Id ="

Based on the information you provided, your query should be:

SELECT Id, StageName, ( SELECT Name, Email FROM Billings__r ) FROM Opportunity WHERE ID = '0011000002mfTil'