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
minciminci 

Strange compilation error

I wrote this code :

 

List<Contact> contactsToCount = [Select Id, Account from Contact where Account in : account_id_list];

Tkan i got an compilation error saying that there is not sych a field

Account in sObject contact.

Contact is being given by salesforce ans so the field Account (Label : Account Name).

Can someone tell me what is the p[roblem?

Thanks!

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

Account is the relationship name between contact and account, and thus you can't select it.

 

You can get the account id, using the following:

 

 

List<Contact> contactsToCount = [Select Id, AccountId from Contact where Account in : account_id_list];

 

 

or the account name using the following:

 

 

List<Contact> contactsToCount = [Select Id, Account.Name from Contact where Account in : account_id_list];

 

 

 

 

 

 

All Answers

bob_buzzardbob_buzzard

Account is the relationship name between contact and account, and thus you can't select it.

 

You can get the account id, using the following:

 

 

List<Contact> contactsToCount = [Select Id, AccountId from Contact where Account in : account_id_list];

 

 

or the account name using the following:

 

 

List<Contact> contactsToCount = [Select Id, Account.Name from Contact where Account in : account_id_list];

 

 

 

 

 

 

This was selected as the best answer
minciminci

Thank you!!! :-) Solved!