651
Scenario:
Need to do Totals of Stages in Opportunity for the entire org.
Thought Process:
- What are the columns involved? Answer: StageName and Count or Total
- What methods will we utilize to achieve these results? Answer: Group By SOQL Statement with Count.
- What UI to built this neat logic? Answer: Apex Controller and VisualForce Page
- Need to achieve this type of reporting for casino online the user:
Solution:
- Use Eclipse IDE or SOQL Explorer to create your SOQL Statement.
-
SELECT StageName, Count(Name) ce
FROM Opportunity GROUP BY StageName
- Second create Apex Controller name what you like I named it TTL_Lesson, with your logic
public class TTL_Lesson{
//Define your variables public class OppStageHolder { public String OPP {get; set;} public Integer TTL_Opp {get; set;} //Empty Array public OppStageHolder (){} } //Results will be placed within this List public List queryResults{ get; set; }
//Your Page
public PageReference TTL() {
AggregateResult[] groupedResults = [SELECT StageName,
Count(Name) ce FROM Opportunity
GROUP BY StageName]; System.Debug("zzavg " groupedResults.size()); //Define your List queryResults = new List();
for (AggregateResult ard : groupedResults) {
OppStageHolder myObject = new OppStageHolder();
myObject.OPP = String.valueOf(ard.get(“StageName”));
myObject.TTL_Opp = (Integer) ard.get(“ce”);
queryResults.add(myObject);
}
return Page.TTL;
}
}
Now create your VF Page to call this and display it whenever the user clicks on this page:
Stage
Count
End result is the image on top
zp8497586rq