+ Start a Discussion
SFDC BayyaSFDC Bayya 

i am writting a simple query but its giving an error

select id,name, (select id  from contact) from account where id =:accountid

i dont understand where i am going wrong can any one guide me
Use it as:

List<Account> accList = [Select id,name, (Select id  from Contacts) from Account where id =:accountid];

SFDC BayyaSFDC Bayya
thanks for ur reply.........but its throwing an error 'accountid' does not exist
You cant just add "contact" , while doing parent to child query you need to use the relationship name to query it. In this case it should be "Contacts"
Deepak Kumar ShyoranDeepak Kumar Shyoran
It’s throws an Error because it may be possible that you miss to define accountId in your code.

Create a List<Id> accountid = new List<Id>() ; which contains Account Id based on which you want to filter account.

Please mark it as best solution to your problem if it does solve your problem.
praveen murugesanpraveen murugesan
Hi Bayya,

you need to assign assign id for that variable before using that.


List<Id> accountid = new List<Id>() ;
for(Account a : [select id from Account]

List<Account> accList = [Select id,name, (Select id  from Contacts) from Account where id =:accountid];

Mark this as best answer if its helps.


Praveen Murugesan.