+ Start a Discussion
Supriyo Ghosh 5Supriyo Ghosh 5 

Unable to filter data

Hi,

I have created on vf page report but when I am click on run button the filter is not working.Please help.

Controller

public class EmpMasterReport
{

    public PageReference EmpList() {
        return null;
    }
    public Employee_Master__c getemp()
    {
      return emp;
    }
   public  Employee_Master__c emp=new Employee_Master__c (); 
   public Transient Date datename{set;get;}  
   public List<Employee_Master__c> EmpList {get;set;}
   public List<Employee_Master__c> PDF_EmpList = new List<Employee_Master__c>();
   public List<Employee_Master__c> getPDF_EmpList(){return PDF_EmpList;}
   public string str{get;set;}
   public date dt;
   
    public EmpMasterReport(ApexPages.StandardController stdController) 
    {
        EmpList = new     List<Employee_Master__c>();
        EmpList = [ SELECT Name,Address__c,Date_Of_Birth__c,Date_Of_Joining__c,Date_of_Leaving__c,Thumbnail__c FROM Employee_Master__c where Active__c=true and Photo__c !=null];
        
    }
    
    public EmpMasterReport()
    {
        EmpList = new     List<Employee_Master__c>();
        EmpList = [ SELECT Name,Address__c,Date_Of_Birth__c,Date_Of_Joining__c,Date_of_Leaving__c,Thumbnail__c FROM Employee_Master__c where Active__c=true and Photo__c !=null];
         
        //PDF_EmpList = [ SELECT Name,Address__c,Date_Of_Birth__c,Date_Of_Joining__c,Date_of_Leaving__c,Thumbnail__c FROM 
        //Employee_Master__c where Active__c=true and Photo__c !=null and Date_Of_Birth__c =: datename];
        
        //system.debug(' PDF_EmpList '+ PDF_EmpList);
    }
    
     public void run()
    {
        //EmpList = new     List<Employee_Master__c>();
        //EmpList = [ SELECT Name,Address__c,Date_Of_Birth__c,Date_Of_Joining__c,Date_of_Leaving__c,Thumbnail__c FROM Employee_Master__c where Active__c=true and Photo__c !=null];
        try
        {
        date dt=emp.Date_Of_Birth__c;
        EmpList =new list<Employee_Master__c>();
        EmpList= [ SELECT Name,Address__c,Date_Of_Birth__c,Date_Of_Joining__c,Date_of_Leaving__c,Thumbnail__c FROM 
        Employee_Master__c where Active__c=true and Photo__c !=null and Date_Of_Birth__c =:dt];
        }
        catch(exception e)
        {
         str=e.getmessage()+e.getlinenumber();
        }
        
        
        system.debug(' PDF_EmpList '+ EmpList);
    }
    
    
    Public pageReference exportReport()
    {
        //pageReference newPage;
        String Br='EmpMasterReport';
        
        system.debug(' datename '+ datename);
        
        PDF_EmpList = [ SELECT Name,Address__c,Date_Of_Birth__c,Date_Of_Joining__c,Date_of_Leaving__c,Thumbnail__c FROM 
        Employee_Master__c where Active__c=true and Photo__c !=null and Date_Of_Birth__c =: datename];
        
        system.debug(' PDF_EmpList '+ PDF_EmpList);
        
        /*if(datename==null)
        {
            ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.INFO,'Please select the Date');
            ApexPages.addMessage(myMsg);
            
        }else
        {*/
            //newPage = new pageReference('/apex/EmpMasterReport_PdfDownloader');
            
            /*Blob pdfpageblob;
            pdfpageblob = newpage.getcontentAsPdf();
            
            Attachment a = new Attachment();
            a.Body = pdfpageblob;
            insert a;*/
        //}
        pageReference newPage = new pageReference('/apex/EmpMasterReport_PdfDownloader');
        newPage.setredirect(true);
        return newPage;
        //return null;
    }
    
    public pageReference pdfreport(){
        system.debug('FSAF');
        pageReference newPage = new pageReference('/apex/EmpMasterReport_PdfDownloader');
        newPage.setredirect(true);
        return newPage;
    }
   
}

vf page
<apex:page id="p1" docType="html-5.0" standardController="Employee_Master__c" extensions="EmpMasterReport" sidebar="false" showHeader="false" cache="true">

<apex:form id="frmid">
<apex:pagemessages ></apex:pagemessages>
<apex:pageBlock title="Employee Master Details" id="Emp_Master">
&nbsp;As On: &nbsp; &nbsp;&nbsp; <apex:input type="date" value="{!datename}"/>
&nbsp; &nbsp;&nbsp; <apex:commandButton Value="Run" action="{!run}" status="generateid" reRender="frmid"/>
<apex:commandButton value="Export As PDF" action="{!exportReport}" status="generateid" reRender="pageid"/> <apex:actionStatus id="actionid" startText="Please Wait...."> </apex:actionStatus>
<apex:pageBlockTable value="{! EmpList }" var="em" border="2"> <apex:column value="{!em.Name}"/>
<apex:column value="{!em.Address__c}"/>
<apex:column value="{!em.Date_Of_Birth__c}"/> <apex:column value="{!em.Date_Of_Joining__c}"/>
<apex:column value="{!em.Date_of_Leaving__c}"/>
<apex:column value="{!em.Thumbnail__c}"/> </apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Pankaj_GanwaniPankaj_Ganwani
Hi,

Remove Transient keyword from the below mentioned code statement:

 public Transient Date datename{set;get;}  
Naval Sharma4Naval Sharma4
Hi Supriyo,

I think you are doing wrong here.

<apex:input type="date" value="{!datename}"/>

above element should be declared as below.

<apex:inputField value="{!emp.Date_Of_Birth__c}"/>

You are declaring datename as transient and transient doesn't go back to controller with form data when form is submitted.

I hope this will help you.

Thanks,
Naval
Supriyo Ghosh 5Supriyo Ghosh 5
I have tried the code but still it is not working.