You need to sign in to do that
Don't have an account?
Dakota
SOQL Query account record with count contacts
I am trying to write a single query to get an account record and the count of contacts for the account. Can this be done?
Ex:
SELECT Name,Id,BillingState, (SELECT count() FROM Contact Where Contact.AccountID = Id) FROM Account WHERE Name like '%Test%'"
Thank You
Dakota
Hello Friend,
The folowing link should satisfy your answer
http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_soql_select_agg_functions.htm
I appreciate the response, however the referred page does not help. I am looking for the correct sytax for a subquery like my example.
I want to get a single record from the Account table and get a count on Contact for the Account record.
Thank You
Dakota
Dont reckon you can do COUNT() in an inner query.
This query kinda returns what you're after
Select AccountId, Count(Name) from Contact group by AccountId
If you're just after how to formulate an inner query, then here goes
Select Id, Name, (Select Id, Name from Contacts) from Account
If you want to reference a bind variable in your query, then it must be prefixed with a colon, eg
Select Id, Name, (Select Id, Name from Contacts) from Account where Id = :accountId