0

Page:

<apex:page controller="statement" >
<apex:form >
<apex:outputLabel value="From Date"/>
<apex:inputText value="{!fromDate}"/><br/>
<apex:outputLabel value="TO Date"/>
<apex:inputText value="{!toDate}"/><br/> <br/>
<apex:commandButton value="Download" action="{!show}"/>
</apex:form>
</apex:page>

Code:

public class statement {
    list<Account> acc; 
    public PageReference show() {
        acc = new list<Account>();
        acc= [select id,name,industry from Account where date =:fromdate]
        return acc;
    }
    public String toDate { get; set; }
    public String fromDate { get; set; }
}

im struck here while its asking return

2
  • 2
    You defined show() as a PageReference, however you return List<Account>. It's the problem.
    – Cray Kao
    Commented Apr 30, 2014 at 17:12
  • no its not working i tried it earlier
    – user8126
    Commented Apr 30, 2014 at 17:14

2 Answers 2

2

Try the modification

Page

<apex:page controller="statement" >
  <apex:form >
    <apex:outputLabel value="From Date"/>
    <apex:inputText value="{!fromDate}"/><br/>
    <apex:outputLabel value="TO Date"/>
    <apex:inputText value="{!toDate}"/><br/> <br/>
    <apex:commandButton value="Download" action="{!show}"/>
  </apex:form>
  Output: {!acc}
</apex:page>

Class

public class statement {
    public list<Account> acc {get; private set;}
    public void show() {
        Date df = Date.ValueOf(fromdate);
        Date dt = Date.ValueOf(toDate);
        acc= [ select id,name,industry from Account where createddate >= :df AND createddate < :dt ];
    }
    public String toDate { get; set; }
    public String fromDate { get; set; }
    public statement(){
        acc = new list<Account>();
    }
}

The screen output

enter image description here

2
  • actually i did not create any field on account as date so i used created date as field and modified soql to ctreateddate but still getting this error statement Compile Error: Invalid bind expression type of String for column of type Datetime at line 4 column 72
    – user8126
    Commented Apr 30, 2014 at 17:21
  • Use either date.valueof() or date.parse() to parse the string to date. See the docuement for details salesforce.com/us/developer/docs/apexcode/Content/…
    – Cray Kao
    Commented Apr 30, 2014 at 17:35
0

There are many issue, one bing that I do not see a way for you to display the return value. Are you trying to display the results?

Lets start by the 1st main issue that you have the method defined as returning a page reference but you are returning a list of accounts: it should be

public List<Account> show() {
        acc = new list<Account>();
        acc= [select id,name,industry from Account where date =:fromdate]
        return acc;
    }

You must log in to answer this question.

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