You need to sign in to do that
Don't have an account?

having trouble rerendering data on VF page
Hello all, I am having issues trying to rerender data on my VF page. My VF page has a place to enter a date. It should then use that date in the controller SOQL to filter records by. Then it should refresh the section of the VF page that contains the records using the date entered. Can someone please help me with this? Thanks.
<apex:page controller="ForecastController" sidebar="false" tabStyle="Opportunity" docType="html-5.0"> <style> table { border-collapse: collapse; width: 100%; } th { text-align: left; padding: 4px; width:100px; } td { text-align: left; padding: 4px; } tr:nth-child(even) {background-color: #cccccc;} </style> <apex:sectionHeader title="Opportunities" subtitle="Forecast Review" description="Please enter the date below you would like to use for historical data."/> <apex:form id="searchForm"> <apex:PageBlock mode="edit"> <apex:pageblockSection id="searchBlockSection"> <apex:pageBlockSectionItem id="searchBlockSectionItem"> <apex:outputLabel >Enter Date (Format: YYYY-MM-DD)</apex:outputLabel> <apex:panelGroup > <apex:inputtext id="searchDate" value="{!searchDate}" /> <strong> <apex:commandButton Id="btnSearch" action="{!search}" rerender="renderBlock" status="status" title="Search" value="Search" > </apex:commandButton> </strong> </apex:panelGroup> </apex:pageBlockSectionItem> </apex:pageblockSection> <apex:actionStatus id="status" startText="Searching... please wait..."/> <apex:repeat value="{!forecasts}" var="c" > <apex:pageBlock title="Close Date (Forecasted) {!c.month}" > <apex:repeat value="{!c.territories}" var="t" > <apex:pageBlock title="Territory {!t}" > <!-- access map variables --> <table> <tr> <th>Account Name</th> <th>Territory Manager</th> <th>Stage</th> <th>Prev Stage</th> <th>AD/RBD Close Date</th> <th>Prev AD/RBD Close Date</th> <th>Close Date</th> <th>Prev Close Date</th> <th>Opportunity Name</th> <th>Total FS + Modules</th> <th>Prev Total FS + Modules</th> <th>Total Instr Rev</th> <th>Prev Total Instr Rev</th> </tr> <apex:repeat var="opps" value="{!opportunities}" > <apex:variable var="v" value="" rendered="{!IF(c.month=opps.Close_Month_Forecasted__c && t=opps.Account.Terr_From_Zip__c,true,false)}" id="renderBlock"> <tr> <td style="width:300px;"> {!opps.Account.Name} </td> <td> {!opps.Account.Territory_Manager__c} </td> <td>{!opps.StageName}</td> <td> <apex:outputText rendered="{!IF(opps.Opportunity_Snapshots__r.size > 0,true,false)}"> {!opps.Opportunity_Snapshots__r[0].Stage__c} </apex:outputText> </td> <td> <apex:outputText value="{0,date,MM-dd-yyyy}"> <apex:param value="{!opps.AD_RBD_Forecast_Close_Date__c}"/> </apex:outputText> </td> <td> <apex:outputText value="{0,date,MM-dd-yyyy}" rendered="{!IF(opps.Opportunity_Snapshots__r.size > 0,true,false)}"> <apex:param value="{!opps.Opportunity_Snapshots__r[0].ADRBD_Forecast_Close_Date__c}" /> </apex:outputText> </td> <td> <apex:outputText value="{0,date,MM-dd-yyyy}"> <apex:param value="{!opps.CloseDate}"/> </apex:outputText> </td> <td> <apex:outputText value="{0,date,MM-dd-yyyy}" rendered="{!IF(opps.Opportunity_Snapshots__r.size > 0,true,false)}"> <apex:param value="{!opps.Opportunity_Snapshots__r[0].Close_Date__c}" /> </apex:outputText> </td> <td style="width:250px;">{!opps.Name}</td> <td>{!opps.Total_FS_Modules__c}</td> <td> <apex:outputText rendered="{!IF(opps.Opportunity_Snapshots__r.size > 0,true,false)}"> {!opps.Opportunity_Snapshots__r[0].Total_FS_Modules__c} </apex:outputText> </td> <td> <apex:outputText value="{0,number,currency}"> <apex:param value="{!opps.Total_Instr_Revenue__c}"/> </apex:outputText></td> <td> <apex:outputText value="{0,number,currency}" rendered="{!IF(opps.Opportunity_Snapshots__r.size > 0,true,false)}"> <apex:param value="{!opps.Opportunity_Snapshots__r[0].Total_Instr_Revenue__c}" /> </apex:outputText> </td> </tr> </apex:variable> </apex:repeat> </table> </apex:pageBlock> </apex:repeat> </apex:pageBlock> </apex:repeat> </apex:PageBlock> </apex:form> </apex:page>
public class ForecastController { public Map<String, Map<String, List<Opportunity>>> values {get;set;} public List<ForecastWrapper> forecasts {get;set;} public List<Opportunity> notForecasted {get;set;} public List<Opportunity> forecasted {get;set;} public List<Opportunity> opportunities {get;set;} public List<Opportunity> searchResults {get;set;} public Date startSearch {get;set;} public Date endSearch {get;set;} // Create Constructor public ForecastController(){ // Load all the data into a map Map<String, Map<String, List<Opportunity>>> values = new Map<String, Map<String, List<Opportunity>>>(); // queries for opps whose stageName = closed recognized but were not forecasted ***NOTE THERE SHOULD BE FIELDS ADDED TO VF PAGE THAT ASK FOR START & END DATES AND ARE THEN USED IN THIS QUERY WHERE CloseDate >= START DATE & <= END DATE notForecasted = [SELECT Id, Name, Account.Name, Account.Territory_Manager__c, StageName, AD_RBD_Forecast_Close_Date__c, CloseDate, Forecastable__c, Forecasted_Close_Date_30_60_90__c, Owner.Name, RecordType.Name, Total_FS_Modules__c, Total_Instr_Revenue__c, Opp_Safe_ID__c, Close_Month_Forecasted__c, Account.Terr_From_Zip__c, (Select Id FROM Opportunity_Snapshots__r) FROM Opportunity WHERE (NOT Name LIKE 'Test') AND (Account.BillingCountryCode = 'US' OR Account.BillingCountryCode = 'CA') AND Forecastable__c = false AND StageName = 'Closed / Recognized' AND CloseDate = THIS_MONTH ORDER BY Account.Name]; // queries opps for currently forecasted records along with subquery of opportunity_snapshot__c -- This shows opps that are now forecasted along with their snapshots if they were also forecasted on the searchDate **NOTE THIS SHOULD USE THE DATE FROM VF PAGE IN THE SUBQUERY TO FIND THOSE SNAPSHOT RECORDS THAT WERE CREATED ON searchDate. I don't know how to make this work. foreCasted = [SELECT Id, Name, Account.Name, Account.Territory_Manager__c, StageName, AD_RBD_Forecast_Close_Date__c, CloseDate, Forecastable__c, Forecasted_Close_Date_30_60_90__c, Owner.Name, RecordType.Name, Total_FS_Modules__c, Total_Instr_Revenue__c, Opp_Safe_ID__c, Close_Month_Forecasted__c, Account.Terr_From_Zip__c, (Select Id, Account_Name__c, ADRBD_Forecast_Close_Date__c, Close_Date__c, Close_Month_Forecasted__c, Install_Date_Instruments_only__c, Opportunity__c, Opportunity_Name__c, Opp_Safe_ID__c, Quantity__c, Stage__c, Territory__c, Territory_Manager__c, Total_FS_Modules__c, Total_Instr_Revenue__c, Total_Price__c, CreatedDate FROM Opportunity_Snapshots__r Where DAY_ONLY(createdDate) >=: startSearch AND DAY_ONLY(createdDate) <=: endSearch) FROM Opportunity WHERE (NOT Name LIKE 'Test') AND (Account.BillingCountryCode = 'US' OR Account.BillingCountryCode = 'CA') AND Forecastable__c = true AND Forecasted_Close_Date_30_60_90__c <> null ORDER BY Account.Name ]; // Need to query for snapshots that are not included in the foreCasted List but were created on searchDate -- This will show records that were previously forecasted on searchDate but are no longer showing as forecasted. // add both notForecasted & forecasted Lists to Opportunities List Opportunities = new List<Opportunity>(notForecasted); Opportunities.addAll(forecasted); // Search through all Opportunities List and get both the Close_Month_Forecasted__c & Account.Terr_From_Zip__c and build Map to display on VFP for(Opportunity record: Opportunities) { Map<String, List<Opportunity>> dateRange = values.get(record.Close_Month_Forecasted__c); if(dateRange == null) { values.put(record.Close_Month_Forecasted__c, dateRange = new Map<String, List<Opportunity>>()); } List<Opportunity> territoryList = dateRange.get(record.Account.Terr_From_Zip__c); if(territoryList == null) { dateRange.put(record.Account.Terr_From_Zip__c, territoryList = new List<Opportunity>()); } territoryList.add(record); } forecasts = new ForecastWrapper[0]; // Load the "keys" into our specified order List<String> months = new List<String>(values.keySet()); months.sort(); for(String month: months) { Map<String, List<Opportunity>> territoryList = values.get(month); String[] territories = new List<String>(territoryList.keySet()); territories.sort(); ForecastWrapper wrap = new ForecastWrapper(); wrap.month = month; wrap.territories = territories; forecasts.add(wrap); } } public Date searchDate { get { return searchDate; } set; } public PageReference search(){ if(SearchResults == null){ SearchResults = new List<Opportunity>(); } else { SearchResults.Clear(); } Date startSearch = searchDate - 1; Date endSearch = searchDate + 1; String qry = 'SELECT Id, Name, Account.Name, Account.Territory_Manager__c, StageName, AD_RBD_Forecast_Close_Date__c, CloseDate, Forecastable__c, Forecasted_Close_Date_30_60_90__c, Owner.Name, RecordType.Name, Total_FS_Modules__c, Total_Instr_Revenue__c, Opp_Safe_ID__c, Health_System_Opportunity__c, Close_Month_Forecasted__c, Account.Terr_From_Zip__c,(Select Id, Account_Name__c, ADRBD_Forecast_Close_Date__c, Close_Date__c, Close_Month_Forecasted__c, Install_Date_Instruments_only__c, Opportunity__c, Opportunity_Name__c, Opp_Safe_ID__c, Quantity__c, Stage__c, Territory__c, Territory_Manager__c, Total_FS_Modules__c, Total_Instr_Revenue__c, Total_Price__c, CreatedDate FROM Opportunity_Snapshots__r Where DAY_ONLY(createdDate) >=:' + startSearch + ' AND DAY_ONLY(createdDate) <=:' + endSearch + ') FROM Opportunity WHERE (NOT Name LIKE \'Test\') AND (Account.BillingCountryCode = \'US\' OR Account.BillingCountryCode = \'CA\') AND Forecastable__c = true AND Forecasted_Close_Date_30_60_90__c <> null ORDER BY Account.Name' ; SearchResults = Database.query(qry); return null; } // Defines Wrapper data types public class ForecastWrapper { public String month {get;set;} public String[] territories {get;set;} } }
Where is SearchResults being used in the VF page? Also you might want to re-render the whole table after button is clicked.

That is probably part of the problem. I don't know how to fix it to make it work properly. Any ideas? If so, can you please provide sample code? Thanks