A sales team needs to track the number of opportunities at each stage of the sales pipeline. This information is crucial for understanding sales progress, identifying bottlenecks, and forecasting revenue.
Implement an Apex method that counts the number of opportunities at each stage and returns the results as a map. This map can be used to create visual representations of the sales pipeline, such as bar charts or pie charts, helping management understand the current state of sales activities and make informed decisions.
Complete the following apex code to satisfy this business requirements.
Instructions
1. The apex method must accepts a list of opportunities
2. Declare a map with stage name as key and the number of opportunities for each stage as value.
3. Return the map.
Sample opportunities
Id | Stage name |
---|---|
006QE0000048gBF | Proposal |
006QE0000048hBF | Proposal |
006QE0000048iBF | Proposal |
Assume the List<Opportunity> allOpportunities contains all records from the above table.
Map<String, Integer> StageCountMap = OpportunityListManager.getRecordsByStageName(AllOpportunities);
Result - The map will contains
{
"Proposal" => 3
}
Use the apex map methods to map the key value pairs in apex
Click here to view all apex map practice examples.