6

I'm trying to write a SOQL query that will retrieve a list of Content sObjects and return it's related child Attribute sObjects.

First I wrote the SOQL query to grab the parent records, and it returns the expected results:

SELECT cms__Name__c, cms__Published_Start_Date__c FROM cms__Content__c WHERE cms__Published_Start_Date__c <= 2017-03-22T18:14:26.128Z AND cms__Content_Type__r.Name = 'CT-000068' LIMIT 10

The problem comes when I try to add the inner query to select the Attribute records. The following is the same query with the addition of the inner query:

SELECT cms__Name__c, cms__Published_Start_Date__c, (SELECT cms__Name__c, cms__Value__c, cms__Type__c, cms__Language__c from cms__Attribute__r) FROM cms__Content__c WHERE cms__Published_Start_Date__c <= 2017-03-22T18:14:26.128Z AND cms__Content_Type__r.Name = 'CT-000068' LIMIT 10

You'll notice I am querying on the relationship in the inner query, denoted by use of cms__Attribute__r. I've confirmed in workbench this is in fact the name of the relationship:

relationship name=cms__Attribute__r

So what's going on here? I would expect that this would return me a List of Content records, each record with their child list of Attribute records.

Thinking maybe developer console just wasn't smart enough to visually display a 1:M relationship, I tried to run the query in my APEX code as well, but no luck.

Here's the full exception I've received:

cms__Type__c, cms__Language__c from cms__Attribute__r) FROM cms__Content__c ^

ERROR at Row:1:Column:125 Didn't understand relationship 'cms__Attribute__r' 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.

I believe I did - what else am I missing?

1 Answer 1

6

You missed the s. Notice the describe says the relationship name is cms__Attributes__r, but you have cms__Attribute__r.

Invalid

(SELECT ... FROM cms__Attribute__r)

Valid

(SELECT ... FROM cms__Attributes__r)
3
  • 1
    Ahhhh of course, thank you! I can accept this as correct in 9 minutes
    – splatto
    Commented Mar 22, 2017 at 20:17
  • 1
    @splatto And the limit has elapsed. Welcome to SFSE!
    – Adrian Larson
    Commented Mar 22, 2017 at 20:43
  • 1
    Done and done! @Adrian Larson
    – splatto
    Commented Mar 22, 2017 at 20:52

You must log in to answer this question.

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