You need to sign in to do that
Don't have an account?
Andrew Perez
Date search criteria
I am getting an error when I try to search for anything using the date fields.
VF:
Controller:
VF:
<apex:page controller="Engagements_Search_Controller" action="{!searchEng}" > <script type="text/javascript"> window.onload=function() { // document.getElementById("{!$Component.thePb.thepbs.engName}").focus(); } </script> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <script type="text/javascript"> function resetForm(ele) { $(ele).closest('form').find("input[type=text], textarea").val(""); return false; } </script> <apex:form id="pageForm"> <apex:pageBlock id="thePb" title="Engagements Details To Search"> <apex:pageblockSection id="thepbs" columns="3" collapsible="true"> <apex:inputField value="{!eng.Name}" required="false" id="engName"/> <apex:inputfield value="{!eng.Company_Name__c}" id="companyName"/> <apex:inputfield value="{!eng.Ultimate_Parent_Company__c}" id="ultCompany"/> </apex:pageblockSection> <apex:pageblockSection id="pbInfo" > <apex:inputfield value="{!eng.Unit_Name__c}" label="Unit" id="unitName"/> <apex:inputfield value="{!eng.Country__c}" id="country"/> <apex:inputField value="{!eng.Scope_of_BR_Area__c}" id="area" label="Area"/> <apex:inputfield value="{!eng.Scope_of_BR_Theme__c}" label="Theme" id="theme"/> </apex:pageblockSection> <apex:pageblockSection columns="3" collapsible="true" id="pbSIC"> <apex:inputField value="{!eng.Additional_SIC_Sector__c}" label="Sector" id="sector"/> <apex:inputfield value="{!eng.Additional_SIC_Industry__c}" label="Industry" id="industry" /> </apex:pageblockSection> <apex:pageblockSection id="pbDate"> <apex:inputfield value="{!eng.SIC_Final__c}" id="sicFinal" /> <apex:outputLink value="https://www.osha.gov/pls/imis/sicsearch.html?p_sic=&p_search=" style="font-weight:bold;" target="_blank">SIC Lookup</apex:outputLink> <apex:inputfield value="{!eng.BR_Start_Date__c}" id="brDate" /><br></br> <apex:inputfield value="{!eng.Project_Start_Date__c}" id="projectDate"/> </apex:pageblockSection> <apex:pageblockButtons location="bottom"> <apex:commandButton value="Search" action="{!searchEng}"/> <apex:commandButton value="Reset" action="{!reset}"/> </apex:pageblockButtons> </apex:pageBlock> <apex:pageblock > <div align="center"> <a href="https://cs25.salesforce.com/search/SearchResults?str=%22Sample+Text*%22&search=Search&sen=a0i&sen=a0i&searchType=2">Exact Keyword(s) Text Search (Note: replace the Sample Text)</a> <a href="https://cs25.salesforce.com/search/SearchResults?searchType=2&str=Sample+Text&search=Search&sen=a0i">All Keyword(s) Text Search (Note: replace the Sample Text)</a> </div> </apex:pageblock> <apex:pageBlock title="Engagements Details" id="noRec" rendered="{! IF( engagementList != null && engagementList.size ==0 , true, false)}" > <apex:outputPanel > <h1>No Records Found </h1> </apex:outputPanel> </apex:pageBlock> <apex:pageBlock title="Engagements Details (Total List Size: {!total_size})" id="details" rendered="{! IF( engagementList != null && engagementList.size >0, true, false)}" > <apex:pageBlockTable value="{!engagementList}" var="a"> <apex:column headerValue="Engagements Name"> <apex:outputLink target="_blank" value="/{!a.id}">{!a.Name}</apex:outputLink> </apex:column> <!-- If you want facet style you can add like this. <apex:column > <apex:facet name="header">Link Name</apex:facet> <apex:outputLink target="_blank" value="/{!a.id}">{!a.Name}</apex:outputLink> </apex:column> --> <apex:column value="{!a.Can_t_be_used_External__c}" headerValue="No Name Drop"/> <apex:column value="{!a.Pending_Go_No_Go_Canceled__c}" headerValue="Go/No-Go"/> <apex:column value="{!a.Additional_SIC_Sector__c}" headerValue="Sector"/> <apex:column value="{!a.Additional_SIC_Industry__c}" headerValue="Industry"/> <apex:column value="{!a.SIC_Final__c}" headerValue="SIC Final"/> <apex:column value="{!a.Unit_Name__c}" headerValue="Unit Name"/> <apex:column value="{!a.Company_Name__c}" headerValue="Company Name"/> <apex:column value="{!a.Ultimate_Parent_Company__c}" headerValue="Ultimate Parent Company"/> <apex:column value="{!a.Actual_Benefits__c}" headerValue="Actual Benefits"/> <apex:column value="{!a.BR_Start_Date__c}" headerValue="BR Start"/> <apex:column value="{!a.Project_Start_Date__c}" headerValue="Project Start"/> </apex:pageBlockTable> <apex:pageblockButtons > <apex:commandButton value="First Page" rerender="details" action="{!FirstPage}" disabled="{!prev}"/> <apex:commandButton value="Previous" rerender="details" action="{!previous}" disabled="{!prev}"/> <apex:commandButton value="Next" rerender="details" action="{!next}" disabled="{!nxt}"/> <apex:commandButton value="Last Page" rerender="details" action="{!LastPage}" disabled="{!nxt}"/> <apex:facet name="footer">Showing Page # {!pageNumber} of {!totalPages}</apex:facet> </apex:pageblockButtons> </apex:pageBlock> </apex:form> </apex:page>
Controller:
public with sharing class Engagements_Search_Controller { public Engagements__c eng{get;set;} public List<Engagements__c> engagementList {get;set;} // create a list of strings to hold the conditions List<string> conditions = new List<string>(); private integer totalRecs = 0; private integer OffsetSize = 0; private integer LimitSize= 25; public integer total_size; //used to show user the total size of the list public Integer page{get;set;} public Integer startIdx{get;set;} public Integer endIdx{get;set;} public Integer totalPages{get;set;} public Integer totalRecords{get;set;} public Engagements_Search_Controller(){ system.debug('==>Engagements_Search_Controller is calling==>'); eng = new Engagements__c(); //engagementList = new List<refount>(); } public void searchEng(){ totalRecs = 0; OffsetSize = 0; if(engagementList !=null && engagementList.size()>0){ engagementList=null; } searchEngagementss (); conditions.clear(); } public Void searchEngagementss(){ System.debug('Total Records is ==>'+totalRecs); System.debug('OffsetSize is ==>'+OffsetSize); if(engagementList != null && !engagementList.isEmpty()){ engagementList.clear(); } String strQuery ='SELECT Name,Pending_Go_No_Go_Canceled__c,Additional_SIC_Sector__c, Additional_SIC_Industry__c,Can_t_be_used_external__c, SIC_Final__c, Unit_Name__c, Company_Name__c, Ultimate_Parent_Company__c, Actual_Benefits__c, Country__c, BR_Start_Date__c, Project_Start_Date__c,Scope_of_BR_Area__c,Scope_of_BR_Theme__c From Engagements__c '; if(eng.Name !=null && eng.Name !=''){ conditions.add('Name Like \'%' +eng.Name +'%\' '); } if(eng.Additional_SIC_Sector__c !=null && eng.Additional_SIC_Sector__c !=''){ conditions.add('Additional_SIC_Sector__c Includes (\'' +eng.Additional_SIC_Sector__c +'\') '); } if(eng.Additional_SIC_Industry__c !=null && eng.Additional_SIC_Industry__c !=''){ conditions.add('Additional_SIC_Industry__c Includes (\'' +eng.Additional_SIC_Industry__c +'\') '); } if(eng.Scope_of_BR_Area__c !=null && eng.Scope_of_BR_Area__c !=''){ conditions.add('Scope_of_BR_Area__c Includes (\'' +eng.Scope_of_BR_Area__c +'\') '); } if(eng.Scope_of_BR_Theme__c !=null && eng.Scope_of_BR_Theme__c !=''){ conditions.add('Scope_of_BR_Theme__c Includes (\'' +eng.Scope_of_BR_Theme__c +'\') '); } if(eng.SIC_Final__c !=null && eng.SIC_Final__c !=''){ conditions.add('SIC_Final__c Like\'%' +eng.SIC_Final__c +'%\' '); } if(eng.Unit_Name__c !=null && eng.Unit_Name__c !=''){ conditions.add('Unit_Name__c Like\'%' +eng.Unit_Name__c +'%\' '); } if(eng.Company_Name__c !=null && eng.Company_Name__c !=''){ conditions.add('Company_Name__c Like\'%' +eng.Company_Name__c +'%\' '); } if(eng.Ultimate_Parent_Company__c !=null && eng.Ultimate_Parent_Company__c !=''){ conditions.add('Ultimate_Parent_Company__c Like\'%' +eng.Ultimate_Parent_Company__c +'%\' '); } if(eng.Country__c !=null && eng.Country__c !=''){ conditions.add('Country__c Like\'%' +eng.Country__c +'%\' '); } if(eng.BR_Start_Date__c !=null){ conditions.add('BR_Start_Date__c >= (\'' +eng.BR_Start_Date__c +'\') '); } if(eng.Project_Start_Date__c !=null){ conditions.add('Project_Start_Date__c >= (\'' +eng.Project_Start_Date__c +'\') '); } if(eng.Can_t_be_used_external__c !=null && eng.Can_t_be_used_external__c != FALSE){ conditions.add('Can_t_be_used_external__c == (\'' +eng.Can_t_be_used_external__c +'\') '); } if (conditions.size() > 0) { strQuery += ' WHERE ' + conditions[0]; for (Integer i = 1; i < conditions.size(); i++) strQuery += ' AND ' + conditions[i]; } if(totalRecs !=null && totalRecs ==0){ List<Engagements__c> engTemp = Database.query(strQuery); totalRecs = (engTemp !=null &&engTemp.size()>0)?engTemp.size():0; } system.debug('strQuery ==>'+strQuery ); // add sort and limits at the end strQuery += ' ORDER BY Name ASC, Unit_Name__c DESC LIMIT :LimitSize OFFSET :OffsetSize'; engagementList =Database.query(strQuery); //conditions.clear(); //return engagementList.size(); } public void FirstPage() { OffsetSize = 0; searchEngagementss(); } public void previous() { OffsetSize = (OffsetSize-LimitSize); searchEngagementss(); } public void next() { OffsetSize = OffsetSize + LimitSize; searchEngagementss(); } public void LastPage() { OffsetSize = totalrecs - math.mod(totalRecs,LimitSize); searchEngagementss(); } public boolean getprev() { if(OffsetSize == 0){ return true; } else { return false; } } public boolean getnxt() { if((OffsetSize + LimitSize) > totalRecs){ return true; } else { return false; } } public Integer getTotal_size() { return totalRecs; } public Integer getPageNumber() { return OffsetSize/LimitSize + 1; } public Integer getTotalPages() { if (math.mod(totalRecs, LimitSize) > 0) { return totalRecs/LimitSize + 1; } else { return (totalRecs/LimitSize); } } //reset button public PageReference reset() { PageReference newpage = new PageReference(System.currentPageReference().getURL()); newpage.getParameters().clear(); newpage.setRedirect(true); return newpage; } }