0

I'm trying to export records from a custom object have got following visualforce page but, the visualforce page needs be invoked from a custom on list view when I try to add a standard controller and extension then save page showing error CarerLettersViewCSV.page: Unknown constructor 'CarerLettersViewController.CarerLettersViewController(ApexPages.StandardController controller)'

<apex:page standardController="Carer_Letter__c" extensions="CarerLettersViewController" readOnly="true" action="{!exportToExcel}" contentType="application/vnd.ms-excel#LetterSearchData.csv">{!header}
      <apex:repeat value="{!lstwrapper}" var="Carer_Letter__c">
       {!Carer_Letter__c.CarerCardNumber},{!Carer_Letter__c.CardExpiryDate},{!Carer_Letter__c.FirstName},{!Carer_Letter__c.LastName},{!Carer_Letter__c.PrimaryAddress1},{!Carer_Letter__c.PrimaryAddress2},{!Carer_Letter__c.PrimarySuburb},{!Carer_Letter__c.PrimaryState},{!Carer_Letter__c.PrimaryPostcode},{!Carer_Letter__c.PostalAddress1},{!Carer_Letter__c.PostalAddress2},{!Carer_Letter__c.PostalSuburb},{!Carer_Letter__c.PostalState},{!Carer_Letter__c.PostalSuburb},{!Carer_Letter__c.PostalPostcode},{!Carer_Letter__c.CenterlinkCRN},{!Carer_Letter__c.DateOfBirth},{!Carer_Letter__c.Email},{!Carer_Letter__c.LetterType},{!Carer_Letter__c.ApplicationId}
  </apex:repeat>
</apex:page>

following is my controller

public class CarerLettersViewController{

    public string header{get;set;}
    public List<wrapper> lstwrapper {get; set;}

    public class wrapper{
        public string CarerCardNumber {get; set;}
        public string CardExpiryDate {get; set;}
        public string FirstName {get; set;}
        public string LastName {get; set;}

        public string PrimaryAddress1 {get; set;}
        public string PrimaryAddress2 {get; set;}
        public string PrimarySuburb {get; set;}
        public string PrimaryState {get; set;}
        public string PrimaryPostcode {get; set;}

        public string PostalAddress1 {get; set;}
        public string PostalAddress2 {get; set;}
        public string PostalSuburb {get; set;}
        public string PostalState {get; set;} 
        public string PostalPostcode {get; set;} 

        public string CenterlinkCRN {get; set;} 
        public string DateOfBirth {get; set;} 
        public string Email {get; set;} 
        public string LetterType {get; set;} 
        public string ApplicationId {get; set;}         
    }

    public string Filetype {get;set;}
    public boolean isExcel {get;set;}
    public boolean isCsv {get;set;}   


    public CarerLettersViewController(ApexPages.StandardSetController stdController){

            Filetype = '';
            lstwrapper = new List<wrapper>();
            header = 'Carer Card Number,Card Expiry Date,Firstname,Lastname,Primary Address2,Primary Suburb,Primary State,Primary Postcode,Postal Address1,Postal Address2,Postal Suburb,Postal State,Postal Postcode,Status\r\n';                     
    }


    public void exportToExcel(){
          string queryString = 'SELECT Carer_Card_Number__c, Card_Expiry_Date__c, Firstname__c, Lastname__c, Primary_Address1__c, Primary_Address2__c, Primary_Suburb__c, Primary_State__c, Primary_PostCode__c, Postal_Address1__c, Postal_Address2__c, Postal_Suburb__c, Postal_State__c, Postal_Postcode__c, Centrelink_CRN__c, Date_Of_Birth__c, Email__c, LetterType__c, ApplicationID__c FROM Carer_Letter__c'; 
          List<Carer_Letter__c> listOfLettersData = DataBase.Query(queryString);
          system.debug('listOfLettersSearchData :'+listOfLettersData.size());
          if(listOfLettersData.size()>0){
              for(Carer_Letter__c cls :listOfLettersData){
                  wrapper w = new wrapper();
                  w.CarerCardNumber = cls.Carer_Card_Number__c;
                  w.CardExpiryDate = string.valueOf(cls.Card_Expiry_Date__c);
                  w.FirstName = cls.Firstname__c;
                  w.LastName = cls.Lastname__c;
                  w.PrimaryAddress1 = cls.Primary_Address1__c;
                  w.PrimaryAddress2 = cls.Primary_Address2__c;
                  w.PrimarySuburb = cls.Primary_Suburb__c;
                  w.PrimaryState = cls.Primary_State__c;
                  w.PrimaryPostcode = string.valueOf(cls.Primary_PostCode__c);
                  w.PostalAddress1 = cls.Postal_Address1__c;
                  w.PostalAddress2 = cls.Postal_Address2__c;
                  w.PostalSuburb = cls.Postal_Suburb__c;
                  w.PostalState = cls.Postal_State__c;
                  w.PostalPostcode = string.valueOf(cls.Postal_Postcode__c);
                  w.CenterlinkCRN = cls.Centrelink_CRN__c;
                  w.DateOfBirth = string.valueOf(cls.Date_Of_Birth__c);
                  w.Email = cls.Email__c;
                  w.LetterType = cls.LetterType__c;
                  w.ApplicationId = cls.ApplicationID__c;
                  lstwrapper.add(w);               
              }             
          }
          system.debug('lstwrapper :'+lstwrapper.size());
    }


}

When I create a custom button I'm not able see on the list view. can someone please help.

4
  • Are you not getting the export option or list views? Sep 5, 2018 at 4:21
  • the plan is to add a button on the list view of custom object tab which calls this visualforce Sep 5, 2018 at 5:29
  • You mean standard list view? Sep 5, 2018 at 5:31
  • Yes standard list view Sep 5, 2018 at 5:32

1 Answer 1

0

Hi have got this working by change in the variable name in vf page as following i was like object name before

<apex:page standardController="Carer_Letter__c" extensions="CarerLettersViewController" readOnly="true" contentType="application/vnd.ms-excel#LetterSearchData.csv">{!header}
      <apex:repeat value="{!lstwrapper}" var="cl">
       {!cl.CarerCardNumber},{!cl.CardExpiryDate},{!cl.FirstName},{!cl.LastName},{!cl.PrimaryAddress1},{!cl.PrimaryAddress2},{!cl.PrimarySuburb},{!cl.PrimaryState},{!cl.PrimaryPostcode},{!cl.PostalAddress1},{!cl.PostalAddress2},{!cl.PostalSuburb},{!cl.PostalState},{!cl.PostalSuburb},{!cl.PostalPostcode},{!cl.CenterlinkCRN},{!cl.DateOfBirth},{!cl.Email},{!cl.LetterType},{!cl.ApplicationId}
  </apex:repeat>
</apex:page>

and created getter setter for custom object in the controller.

public Carer_Letter__c carerLetter {get; set;}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .