function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Dave DudekDave Dudek 

SOQL query with inner select issue

I'm trying to view contacts of accounts that are related to a custom object we have called Our_Role_Service_Affiliation_for_Account__c. I'm able to see the account name, service name and role name but I can't seem to delve into the accounts.

Here's my two SELECT queries I've tried:

1) 
SELECT Id,Name,(SELECT Name FROM Contacts),(SELECT Id,Service__r.Name,Our_Role__r.Name FROM Our_Role_Service_Affiliation_for_Account__r) FROM Account WHERE Id IN (SELECT Account__r.Id FROM Our_Role_Service_Affiliation_for_Account__c WHERE Our_Role__r != 'Outreach')

ERROR at Row:1:Column:171
The inner select field 'Account__r.Id' cannot have more than one level of relationships


2)
SELECT Name,Account__r.Name,Service__r.Name,Our_Role__r.Name FROM Our_Role_Service_Affiliation_for_Account__c WHERE Our_Role__r.Name != 'Outreach' AND Account__r.BillingState = :place.State_Code__c

Works but doesn't show contacts

 
Lokesh KumarLokesh Kumar
Hi Dave,

Kindly update your 1st SOQL like below add GROUP BY
 
SELECT Id,Name,(SELECT Name FROM Contacts),(SELECT Id,Service__r.Name,Our_Role__r.Name FROM Our_Role_Service_Affiliation_for_Account__r) FROM Account WHERE Id IN (SELECT Account__r.Id FROM Our_Role_Service_Affiliation_for_Account__c WHERE Our_Role__r != 'Outreach' GROUP BY Account__r.Id)

let me know if this help you.
Thanks
Lokesh
Dave DudekDave Dudek
It says "Unknown error parsing query"
brahmaji tammanabrahmaji tammana
Hi

Can you try this ?
 
SELECT Id,Name,(SELECT Name FROM Contacts),(SELECT Id,Service__r.Name,Our_Role__r.Name FROM Our_Role_Service_Affiliation_for_Account__r) FROM Account WHERE Id IN (SELECT Account__c FROM Our_Role_Service_Affiliation_for_Account__c WHERE Our_Role__r != 'Outreach')

Thanks
Brahma
Dave DudekDave Dudek
Still says "Unknown error parsing query"
brahmaji tammanabrahmaji tammana
Hi,

Can you tell the API name of Account relationship in Our_Role_Service_Affiliation_for_Account__c 
brahmaji tammanabrahmaji tammana
SELECT Id,Name,(SELECT Name FROM Contacts),(SELECT Id,Service__r.Name,Our_Role__r.Name FROM Our_Role_Service_Affiliation_for_Account__r) FROM Account WHERE Id IN (SELECT Account__c FROM Our_Role_Service_Affiliation_for_Account__c WHERE Our_Role__r != 'Outreach') 

Please try this.

There was some typo in my earlier post.

Thanks
Dave DudekDave Dudek
yup. it works. thanks!
Rabindra BhowalRabindra Bhowal
Hi 

I am trying to get list of account name from Account object:

SELECT Name FROM Account;

But having following error on developer console query editor 
Unknown error parsing query

Can anybody help me
brahmaji tammanabrahmaji tammana
Try removing semicolon (;) in the end, it is not required from developer console query editor, it is required only in apex logics
 
SELECT Name FROM Account