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
shabbushabbu 

How to fetch count of contacts for picklists value in account

I need to create a button on account, When clicked, this button should show a table which lists all status types and counts of contacts of each status type for that account. Status is picklist field which is having 4 options.

mbhardwajmbhardwaj
create an inline VF page and place that button there. Implement a function on click of the button.
You can use an SOQL like this
[Select Status, count(Id) from Account.Contacts group by Status],
This will return AggregateResult[], Loop thru this and store it in a list which can displayed on the VF page using datatable or pageblocktable..
shabbushabbu
Thank u so much for your reply, i did that one
but problem in soql query

acct=[select Status__c,count(Id) from Account.Contacts group by Status__c];

acct=[select name,[select Status__c,count(Id) from Contacts group by Status__c] from Accounts];

i tried by using these both
can you plz help me in this.........
mbhardwajmbhardwaj
Can you please share the code of VF and controller here.
shabbushabbu

i am going to create a button in account object for that button i am going to write vf and controller......

 

controller:

public with sharing class contstatus {

public contstatus(ApexPages.StandardController controller) {

}
public list<Account> acct{get; set;}
public void countsearch(){
acct=[select Status__c,count(Id) from Account.Contacts group by Status__c];
}

}

 

in VF Page by using page block table i will display the count of contact for status field on account object