• kpeterson85
  • NEWBIE
  • 0 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies

Hi,

 

I have a search form whereby i can search by account name and results are displayed from the case object.  I would now like to search using a start date but i cannot get this to work i.e no results are returnedand no ERROR message displayed!!

 

Can someone plz tell me what i might doing wrong?  THANKS in advance!! 

 

<apex:page id="Cas" controller="CaseController9" sidebar="false">

    <apex:form >
    <apex:pageBlock >      

            <apex:pageBlockSection columns="2">
               
                <apex:pageBlockSectionItem >
                    <apex:outputText value="Account Name"/>
                    <apex:inputText id="accountName" value="{!accountName}"/>
                 </apex:pageBlockSectionItem>
                 
                <apex:pageBlockSectionItem >
                    <apex:outputText value="Start  Date"/>
                    <apex:inputText id="startDate" value="{!startDate}"/>
                 </apex:pageBlockSectionItem>
                                       
            </apex:pageBlockSection>
                       
            <p></p>
            <table>
                <tr>
                <td align="bottom" valign="center">
                    <br></br>
                    <apex:commandButton action="{!search}" value="Search" id="searchBtn" status="Searching"/>                    
                 </td>
                 </tr>
             </table>
    
    <apex:pageBlock tabStyle="Case" id="pagin" rendered="{!IF(Result.size > 0 , true , false)}">
     
        <apex:outputPanel layout="block" styleClass="pSearchShowMore" id="otpNav2">
        
        Total Records Found :&nbsp; <apex:outputText rendered="{!IF(Con.resultSize==10000,true,false)}" >10000 +</apex:outputText><apex:outputText rendered="{!IF(Con.resultSize < 10000,true,false)}">{!Con.resultSize}</apex:outputText>
            <apex:image url="/img/search_prevarrow_disabled.gif" styleClass="prevArrow" rendered="{!NOT(Con.HasPrevious)}"/>
            <apex:image url="/img/search_prevarrow.gif" title="Previous Page" styleClass="prevArrow" rendered="{!Con.HasPrevious}"/>

        <apex:commandLink action="{!Previous}" title="Previous Page" value="Previous Page" reRender="pagin" rendered="{!Con.HasPrevious}"/>

        <apex:outputPanel styleClass="pShowLess noLink" style="color:grey" rendered="{!NOT(Con.HasPrevious)}">Previous Page</apex:outputPanel>&nbsp;
        ({!IF(Con.PageNumber == 1,1,((Con.PageNumber -1) * Con.PageSize)+1)}-{!IF(Con.resultSize < Con.PageSize,Con.resultSize,Con.PageNumber * Con.pageSize)})&nbsp;
        <apex:outputPanel styleClass="pShowLess noLink" style="color:grey" rendered="{!NOT(Con.HasNext)}">Next Page</apex:outputPanel>

        <apex:commandLink title="Next Page" value="Next Page" reRender="pagin" rendered="{!Con.HasNext}" action="{!Next}"/>&nbsp;
            <apex:image url="/img/search_nextarrow.gif" title="Next Page" styleClass="nextArrow" rendered="{!Con.HasNext}"/>
            <apex:image url="/img/search_nextarrow_disabled.gif" rendered="{!NOT(Con.HasNext)}"/>

        </apex:outputPanel>
        <br></br>

    <apex:pageBlock mode="edit" id="Results">
        <apex:pageBlockTable value="{!result}" var="cas" id="data">
           
            <apex:column headerValue="Start Date" value="{!cas.CreatedDate}"/>
            <apex:column headerValue="Account Name" value="{!cas.Account.Name}"/>

        </apex:pageBlockTable>
    </apex:pageBlock>    
            </apex:pageBlock>
        </apex:pageBlock>
    </apex:form>
</apex:page>

 

Public with Sharing Class CaseController9 {

    public String accountname{get;set;}
    public DateTime startDate{get;set;}        
    
    public List<Case> Result
    {
        get  
        {  
            if(con != null)  
                return (List<Case>)con.getRecords();  
            else 
                return null;  
        }  
        set;
        }        
     
    public PageReference search() {
        
        //Search using field Account Name only
        If (startDate==Null && accountname!='')
        {  
            con = new ApexPages.StandardSetController(Database.getQueryLocator([SELECT account.name, createddate FROM Case WHERE Account.Name LIKE :accountname+'%' limit 100]));
            con.setPageSize(200); 
        }
         //Search using field Start Date only
        If (startDate!=Null && accountname=='')
        {  
            con = new ApexPages.StandardSetController(Database.getQueryLocator([SELECT account.name, createddate FROM Case WHERE CreatedDate = :startDate limit 100]));
            con.setPageSize(200); 
        }
           else
        {    
            con = null;
        }         
            return null;        
    }   
             
        public ApexPages.StandardSetController con { get; set; }
        
        public CaseController9()
        {            
            con = new ApexPages.StandardSetController(Database.getQueryLocator([SELECT CreatedDate, account.name FROM Case Order By account.name]));
        }            
    
    public Boolean hasNext
    {
        get
        { return con.getHasNext(); }
        set;
    }        
    
       public Boolean hasPrevious
    {
        get
        { return con.getHasPrevious(); }
        set;
    }    
    
     public Integer pageNumber  
    {  
        get  
        { return con.getPageNumber(); }  
        set; 
    }    
    
    public void next()
    { con.next(); }

    public void previous()  
    { con.previous(); }    
}

 

  • March 07, 2012
  • Like
  • 0