I am creating a visualforce page component to go on the Account Page that will display all related Sales_History__c
records. I would like to include a drop down that will allow the end user to select the year to view. This does not have to be a drop down, it could be an input as well.
EDIT
Okay so here is what I have right now.
Controller:
public class SalesHistoryOverviewController {
public Id AccountId { get; set; }
public String SelectedYear { get; set; }
public List<SelectOption> Options { get; set; }
public SalesHistoryOverviewController() {
SelectedYear = '2017';
Options = new List<SelectOption>();
Options.add(new SelectOption('2017', '2017'));
Options.add(new SelectOption('2016', '2016'));
Options.add(new SelectOption('2015', '2015'));
Options.add(new SelectOption('2014', '2014'));
Options.add(new SelectOption('2013', '2013'));
Options.add(new SelectOption('2012', '2012'));
Options.add(new SelectOption('2011', '2011'));
}
public List<Sales_History__c> Sales_Histories {
get {
return [SELECT Id, Name FROM Sales_History__c WHERE Account_Name__c = :AccountId AND CALENDAR_YEAR(Sale_Date__c) = :Integer.valueOf(SelectedYear)];
}
}
public PageReference Rerender() {
return null;
}
}
Component:
<apex:component controller="SalesHistoryOverviewController">
<apex:attribute name="id_param" assignTo="{!AccountId}" description="..." type="String" required="true"/>
<apex:outputPanel id="componentPanel">
<apex:form>
<apex:selectList value="{!SelectedYear}" multiselect="false">
<apex:selectOptions value="{!Options}"/>
</apex:selectList>
<apex:commandButton value="Filter Records" action="{!Rerender}" rerender="componentPanel" />
</apex:form>
<apex:dataList value="{!Sales_Histories}" var="s">
<apex:outputText value="{s.Name}"/>
<apex:outputText value="{s.Account_Name__c}"/>
<apex:outputText value="{s.Invoice_Number__c}"/>
<apex:outputText value="{s.Sale_Date__c}"/>
<apex:outputText value="{s.Grand_Total__c}"/>
</apex:dataList>
</apex:outputPanel>
Page:
<apex:page standardController="Account">
<s.SalesHistoryOverviewComponent id_param="{!Account.Id}" />
</apex:page>
I put the page on an Account Page Layout and nothing is showing. Not sure where I am going wrong here.
Sales_History__c
records?getId()
method of the standardController class. When it is displayed inline the user can interact with it