You need to sign in to do that
Don't have an account?
ravi chandra 16
SOQL Query
Write a SOQL query that counts the number of active Contacts for each Account in a set.
function readOnly(count){ }
You need to sign in to do that
Don't have an account?
Try this
Now this map accountIdWithContactCount will have count of contacts for each account
You can get the count by passing account Id
Integer count = accountIdWithContactCount.get(accId);
For relationship Queries refer the below links
https://developer.salesforce.com/blogs/developer-relations/2013/05/basic-soql-relationship-queries.html
http://www.salesforce.com/us/developer/docs/dbcom_soql_sosl/Content/sforce_api_calls_soql_relationships.htm
Regards,
Bhanu Mahesh
AggregateResult[] groupedResults = [SELECT COUNT(Id) total, AccountId FROM Contact WHERE IsActive = true GROUP BY AccountId];