You need to sign in to do that
Don't have an account?
jgradw2
Apex SOQL Invalid Type problem
Hello and thank you for responding!
I am misunderstanding an invalid type error I'm receiving. The most simple example is this:
Set<Account>Agencies = new Set<Account>();
Agencies.addAll([SELECT Account.ID, Account.Name FROM Contact WHERE ID = '']);
The error for this assignment would be to the likes of: cannot assign type <List>Contact to type <Set>Account.
Why is the FROM clause object dictating the type of the query? And I need to understand why this does not work because I have other queries that work similarly as this one, and would otherwise require nested subqueries, which are not supported in SOQL.
Thank you very much :)
your query returns contacts, so you can assign that to a set of accounts, you'll need to loop over the results and add the nested account object from the contact into your set.
All Answers
your query returns contacts, so you can assign that to a set of accounts, you'll need to loop over the results and add the nested account object from the contact into your set.
Thank you very much, that does get me the results I need :)