Scenario:
Need to do Totals of Stages in Opportunity for the entire org.
Thought Process:
}
Now create your VF Page to call this and display it whenever the user clicks on this page:
<apex:page controller="TTL_Lesson" action="{!TTL}" showHeader="false" sidebar="false">
<apex:dataTable value="{!queryResults}" var="a" id="theTable" border="2" cellpadding="1" cellspacing="1" bgcolor="#A9D0F5" >
<apex:column >
<apex:facet name="header">Stage</apex:facet>
<apex:outputText value="{!a.OPP}"/>
</apex:column>
<apex:column >
<apex:facet name="header"> Count</apex:facet>
<apex:outputText value="{!a.TTL_Opp}"/>
</apex:column>
</apex:dataTable>
</apex:page>
End result is the image on top
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 the user:
- 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
//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 ListqueryResults{ 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:
<apex:page controller="TTL_Lesson" action="{!TTL}" showHeader="false" sidebar="false">
<apex:dataTable value="{!queryResults}" var="a" id="theTable" border="2" cellpadding="1" cellspacing="1" bgcolor="#A9D0F5" >
<apex:column >
<apex:facet name="header">Stage</apex:facet>
<apex:outputText value="{!a.OPP}"/>
</apex:column>
<apex:column >
<apex:facet name="header"> Count</apex:facet>
<apex:outputText value="{!a.TTL_Opp}"/>
</apex:column>
</apex:dataTable>
</apex:page>
End result is the image on top
No comments:
Post a Comment