You need to sign in to do that
Don't have an account?
Dave Dudek
SOQL query with a subquery to show contacts and accounts located within a state that have a certain custom object relationship
I'm trying to create a SOQL query with a subquery to show contacts and accounts located within a state that have a certain custom object relationship:
Here is my code:
SELECT Id,Name FROM Account WHERE Our_Role_Count__c > 0 AND BillingState = 'NH' AND Id IN (SELECT Account__r.Id,Account__r.Name,Account__r.BillingState, Our_Role__r.Name FROM Our_Role_Service_Affiliation_for_Account__c WHERE Our_Role__r.Name != 'Outreach')
However I get an error: The inner select field 'Account__r.Id' cannot have more than one level of relationships
Here is my code:
SELECT Id,Name FROM Account WHERE Our_Role_Count__c > 0 AND BillingState = 'NH' AND Id IN (SELECT Account__r.Id,Account__r.Name,Account__r.BillingState, Our_Role__r.Name FROM Our_Role_Service_Affiliation_for_Account__c WHERE Our_Role__r.Name != 'Outreach')
However I get an error: The inner select field 'Account__r.Id' cannot have more than one level of relationships
You have to update inner query to keep only single field in SELECT. You cannot put more fields in such inner query. It should contain only field which has matching object type as Id of outer query. In your case, it should be Account Id only. Below is the updated query.
-Thanks,
TK
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
All Answers
You have to update inner query to keep only single field in SELECT. You cannot put more fields in such inner query. It should contain only field which has matching object type as Id of outer query. In your case, it should be Account Id only. Below is the updated query.
-Thanks,
TK
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.