function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
VNVN 

PageReference

Hi,
 
We have a requirement where we need to fetch the filter criteria entered by user in the visualforce page and display the report. I have created 3 picklist field for this and when i click on generate report the report is not accurate.
 
Could anyone please help me with where iam going wrong.
 
The code for is
Code:
...
<apex:pageBlock title="Enter Filter Criteria"> 
<apex:form >
<b>Marketing Domain</b>
<apex:selectList id="domain" size="1" >
<apex:selectOptions value="{!items}"/>
</apex:selectList> 
....

<apex:commandButton value="Generate Report"  action="{!reset}">
</apex:commandButton>
.....

 

The code for controller class is

Code:
....
public Account[] getAccount()
 { 
   accounts = [Select Name,Customer_Rating1__c,Target_Visit__c,salesdistrict__c,Achieved__c,To_Be_Achieved__c from Account where Marketing_Domain__c=:ApexPages.currentPage().getParameters().get('domain')];
      return accounts;
 }
....

public PageReference reset() {
    PageReference newpage = new PageReference(System.currentPageReference().getURL());
    newpage.setRedirect(true);
    return newpage;
  }
...


 Please Help.

Thanks in advance

Priya Nair


 
Best Answer chosen by Admin (Salesforce Developers) 
jwetzlerjwetzler
You need to give your selectlist a value attribute bound to a String in your controller, and then use that String in the where clause of your SOQL, instead of getting the current page parameters. currentPage().getParameters gets your query string so this is not doing what you think it is at all.

Also you are doing way too much work in your reset method.  For one, if you want to get the PageReference of a Visualforce page in your org, you just use PageReference p = Page.myPageName.  And you're setting a redirect which means you're going to lose all of your viewstate, which means you're going to run your query but then redirect to your page, discarding your query result.  All you should have to do is return null, which will cause your page to refresh.

All Answers

jwetzlerjwetzler
You need to give your selectlist a value attribute bound to a String in your controller, and then use that String in the where clause of your SOQL, instead of getting the current page parameters. currentPage().getParameters gets your query string so this is not doing what you think it is at all.

Also you are doing way too much work in your reset method.  For one, if you want to get the PageReference of a Visualforce page in your org, you just use PageReference p = Page.myPageName.  And you're setting a redirect which means you're going to lose all of your viewstate, which means you're going to run your query but then redirect to your page, discarding your query result.  All you should have to do is return null, which will cause your page to refresh.
This was selected as the best answer
VNVN
Thanks a lot for the help...i will modify the code as you suggested.
Mahendiran JayavarmaMahendiran Jayavarma

Hi,

 

can u provide modified code which u did.

 

Thanks,

Mahendiran.