0

I am a beginner in salesforce and I am attempting to write a controller class for a VF page that searches records based on a criteria(Date and status field)

But I am facing the following error:

Unknown constructor 'Newexpensecontroller.Newexpensecontroller(ApexPages.StandardController controller)'

Here is my VF Page

<apex:page standardController="expenses__c" extensions="Newexpensecontroller">
    <apex:form >
        <apex:pageBlock >

            <apex:pageMessages id="pgm"/>

            <apex:pageBlockButtons >
                <apex:commandButton value="Search" action="{!Search}" />
            </apex:pageBlockButtons>
                <apex:pageBlockSection >
            <apex:pageBlockSectionItem >
                <apex:outputLabel for="FromSearch">From Date</apex:outputLabel>
                <apex:inputText value="{!FromSearch}"  id="FromSearch"/>
                </apex:pageBlockSectionItem>

               <apex:pageBlockSectionItem >
                <apex:outputLabel for="ToSearch">To Date</apex:outputLabel>
                <apex:inputText value="{!ToSearch}" id="ToSearch"/>
                </apex:pageBlockSectionItem>
                </apex:pageBlockSection>


            <apex:pageBlockSection >
                <apex:pageBlockSectionItem >

                <apex:outputLabel for="statussearch">Status</apex:outputLabel>
               <apex:selectList id="statussearch" value="{!statussearch}" multiselect="false" size="1">
               <apex:selectOptions value="{!statusItems}"/>
                </apex:selectList>  


                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>

        </apex:pageBlock>

        <apex:pageBlock rendered="{!IF(AND(NOT(ISBLANK(Allexpenses)),Allexpenses.size>0),true,false)}">

            <apex:outputPanel layout="block" styleClass="pSearchShowMore" id="otpNav2">
              Total Records Found: <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" 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" 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>

            <apex:pageBlockSection columns="1">
                <apex:pageBlockTable value="{!Allexpenses}" var="UR">
                    <apex:column headerValue="Name" value="{!UR.Name}"/>  
                     <apex:column headerValue="Date" value="{!UR.Date_of_Expense__c}"/>
                </apex:pageBlockTable>
            </apex:pageBlockSection>

            <apex:outputPanel layout="block" styleClass="pSearchShowMore" id="otpNav">
              Total Records Found: <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" 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" 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>

        </apex:pageBlock>

    </apex:form>
</apex:page>

class:

public class Newexpensecontroller {

            public List<expenses__c> Allexpenses
    {
        get
        {
            if(con != null)
                return (List<expenses__c>)con.getRecords();
            else
                return null ;
        }
        set;}



   // public User usr {get; set;}

    public string statussearch{get;set;}
    public string Fromsearch{get;set;}
    public string Tosearch{get;set;}
   //public List<SelectOption> getstatusItems {get;set;}

    public expenses__c exp{get;set;}

    public string getstatussearch(){

        return statussearch;
    }

     public void setstatussearch(string s){

        statussearch=s;
    }


     public string getFromsearch(){

        return Fromsearch;
    }

     public void setFromsearch(string fd){

        Fromsearch=fd;
    }

     public string getTosearch(){

        return Tosearch;
    }

     public void setTosearch(string Td){

        Tosearch=Td;
         system.debug('Tosearch:'+Tosearch);
    }

    public list<Selectoption> getstatusItems(){

    List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('New','New'));
        options.add(new SelectOption('Pending Approval','Pending Approval'));
        options.add(new SelectOption('Approved','Approved'));
        options.add(new SelectOption('Rejected','Rejected'));
         options.add(new SelectOption('Cancelled','Cancelled'));
        if(Test.isRunningTest()){
            options.add(new SelectOption('test', 'test'));
        } 

        return options;
    }

    //Controller
    public Newexpensecontroller(ApexPages.StandardController con)
    {


    }

    public Newexpensecontroller(ApexPages.StandardsetController control)
    {
        //ApexPages.StandardSetController con;
        //ApexPages.StandardController sc = new ApexPages.standardController();
    con=control;
           Allexpenses = new List<expenses__C>() ;

    // exp=control.getSelected();

    }

     public PageReference Search()
    {   
        if(statussearch != null)
        {
            con = new ApexPages.StandardSetController(Database.getQueryLocator([Select Id, Name,Date_of_Expense__c FROM expenses__c  where status__c =:statussearch and Date_of_Expense__c >=:Date.parse(Fromsearch) and Date_of_Expense__c <=:Date.parse(Tosearch) Order By Name limit 100]));
                   con.setPageSize(5);
            // sets the number of records in each page set

        }
        else
        {
            con = null;
        }
        return null ;
    }

    //Instantiate the StandardSetController
    public ApexPages.StandardSetController con{get; set;}

    //Boolean to check if there are more records after the present displaying records
    public Boolean hasNext
    {
        get
        {
            return con.getHasNext();
        }
        set;
    }

    //Boolean to check if there are more records before the present displaying records
    public Boolean hasPrevious
    {
        get
        {
            return con.getHasPrevious();
        }
        set;
    }

    //Page number of the current displaying records
    public Integer pageNumber
    {
        get
        {
            return con.getPageNumber();
        }
        set;
    }

    //Returns the previous page of records
    public void previous()
    {
        con.previous();
    }

    //Returns the next page of records
    public void next()
    {
        con.next();
    }
}
  • 1
    Can you copy the whole code. <apex:page> tag is missing. – Bhawna Jul 12 '17 at 7:12
0

This seem to be an error of Extension.

A controller extension is any Apex class containing a constructor that takes a single argument of type ApexPages.StandardController or CustomControllerName, where CustomControllerName is the name of a custom controller you want to extend.

Which means you need to add following code in your controller

public Var_Name = new Custom_Object_Name__c();

public Newexpensecontroller(ApexPages.StandardController stdController) {
        this.Var_Name = (Custom_Object_Name__c)stdController.getRecord();
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.