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
Siddharth LakhotiaSiddharth Lakhotia 

I want to display the count of all the stages of opportunity field related to account ? Can somebody suggest the code for it ?

Acccount NameClosed WonClosedLostProgressiveValidation
Acc18452
Acc26524
Acc31907
Acc45656
 I want to display this table on my VF Page. Can anybody recommend code for it 

 
pconpcon
You can do this a couple of ways.  You can either try to generate one (or more) AggregateResult queries to generate this, or query all of the data yourself and then generate the counts.  The building the data set is the hard part, the generating the visualforce display is the easier part.  Below is an example of part of the controller code you'd need
 
public class AccountData {
    public String name {get; set'}
    public Integer closedWon {get; set;}
    public Integer closedLost {get; set;}
    public Integer progressive {get; set;}
    public Integer validation {get; set;}

    public AccountData(String name) {
        this.name = name;
    }

    public void setClosedWon(Integer value) {
        this.closedWon = value;
    }

    // Repeat above for each stage
}

Map<String, AccountData> dataMap = new Map<String, AccountData>();
Map<String, Map<String, Integer>> resultMap = new Map<String, Map<String, String>>();

for (AggregateResult result : [
    select Account.Name,
        StageName,
        Count(Id)
    from Opportunity
    group by Account.Name,
        StageName
]) {
    if (!resultMap.containsKey(result.Account.Name)) {
        resultMap.put(result.Account.Name, new Map<String, Integer>());
        accountData.put(result.Account.Name, new AccountData(result.Account.Name));
    }

    resultMap.get(result.Account.Name).put(result.StageName, (Integer) result.get('expr0'));
}

for (String name : resultMap.keySet()) {
    dataMap.get(name).setClosedWon(resultMap.get(name).get('Closed Won'));
    // Repeat for each stage name
}