0
votes

Account has a field Source_System__c as its parent.

I wanna query Name, Id from Source_System

This query is workable. [SELECT Source_System__r.Name, Source_System__r.Id from Account]

However, I wanna have the value from Source_System can be nested in an object. Like the sub-query's result. But it didn't work.

SELECT (SELECT Name, Id from Source_System) FROM Account
                         ^

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

SELECT (SELECT Name, Id from Source_System__r) FROM Account
                         ^

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

1

1 Answers

0
votes

As I understand from your question Account is child here and Source_System__c is parent.

SELECT Source_System__r.Name, Source_System__r.Id FROM Account

This query will work because your are using child-to-parent relationship. But you can't query like SELECT (SELECT Name, Id from Source_System) FROM Account.

Because the inner query object should be child of account. Here you can use parent-to-child relationship in aggregate query like this:

SELECT Id,Name,
  (
    SELECT id
    FROM Accounts__r
  )
FROM Source_System__c 

Please refer Using Relationship Queries