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
Frank CarterFrank Carter 

visualforce: redirect to result page

Hello, I need help.
I created a vf search page with two input data fields to set. 
When I click the search button the page displays me all the records with a data field included in data range:
User-added image
If I clicks Edit on a row I have the record page with the three buttons Save, Save and New, Cancel.
If I clicks Save or Edit the result of the search disappears.
The target is that when I go back clicking Cancel or Save I have the same page and not a n empty page:
User-added image

vf page:
<apex:page controller="searchBDController" docType="html-5.0" id="pg">

<apex:form >
    <apex:pageBlock title="Billing Details Search Page" >
        <br/>
        <br/>
       <apex:actionRegion >
           <center>
                <apex:outputLabel value="Start Date"/>
                <apex:input value="{!StartDate}" type="date" /><br/>
                <apex:outputLabel value="End Date "/>
                <apex:input value="{!EndDate}" type="date" /> 
               </center>
            </apex:actionRegion>  
    <br/>
        
        	<div align="center" draggable="false" >            
                <apex:commandButton value="Search" action="{!loadData}" style="text-align:left;" />
                
                <apex:commandButton value="Moves to next month" style="text-align:left;" onclick="if(!confirm('If you click ok all the billing details you are viewing will be paid for next month. Are you sure? ')) return false;" action="{!myAction}" />  
			</div>

        
   
    </apex:pageBlock>


        <apex:pageBlock id="pgblk">
 			<apex:pageBlockTable value="{!listBD}" var="b">
					<apex:column value="{!b.Name}"/>
                    <apex:column value="{!b.SF_Opportunity_Id__c}"/>
                    <apex:column value="{!b.Billing_Type__c}"/>
                    <apex:column value="{!b.Billing_Period__c}"/>    
                    <apex:column value="{!b.Monthly_Forecast__c}"/>
                    <apex:column value="{!b.End_of_Billing__c}"/>
                    <apex:column value="{!b.Amount__c}"/>
                    <apex:column value="{!b.Billing_Status__c}"/>
                    <apex:column >
                    <apex:outputLink title="" value="/{!b.Id}/e?retURL=/apex/{!$CurrentPage.Name}" style="font-weight:bold">EDIT</apex:outputLink>
                    </apex:column>
                    
            </apex:pageBlockTable>
  
        </apex:pageBlock>

  


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

controller:
 
public class searchBDController {
    
    public Date StartDate {get;set;}
    public Date EndDate {get;set;}
    private Boolean changed {get;set;}
 
     public ApexPages.StandardSetController setCon {
        get {
            if(setCon == null) {                
                setCon = new ApexPages.StandardSetController(Database.getQueryLocator(
                      [Select Id,SF_Opportunity_Id__c, Name,Billing_Type__c, Billing_Period__c , Monthly_Forecast__c,End_of_Billing__c, Amount__c, Billing_Status__c, Position__c   from Billing_Detail__c Where Monthly_Forecast__c>=:StartDate AND Monthly_Forecast__c <= :EndDate Order by Monthly_Forecast__c]));
                  
               
            }            
            return setCon;
        }
        set;
    }
    
     public List<Billing_Detail__c> listBD {get;set;}
    public String SelectedBdId {get;set;}
            
    public void loadData() {
        listBD = [Select Id,SF_Opportunity_Id__c,Name,Billing_Type__c, Billing_Period__c , Monthly_Forecast__c,End_of_Billing__c, Amount__c, Billing_Status__c, Position__c   from Billing_Detail__c Where Monthly_Forecast__c>=:StartDate AND Monthly_Forecast__c <= :EndDate Order by Monthly_Forecast__c];
    }
    
    //to move monthly forecast
 	public PageReference myAction(){
		MoveBD1.Move1();
        PageReference pageRef = ApexPages.currentPage();
      	pageRef.setRedirect(true);
      	return pageRef;
	} 
   

}
Can someone give me an help??


Thanks
Abdul KhatriAbdul Khatri
I don't there is a quick way to achieve you requiement.

For now the only way I can think you can achieve this is create a Custom Object "Billing Search" with the following fields

1. UserId --> Lookup to User who is perorming the search
2. StartDate
3. EndDate

Upsert the record based on the UserId so that there is only one record per user in this object which will be last search he/she made. This will also help you to retreive last search user did, when he is returning back to this page later on even after rebooting the machine.

Let me know if that works for you.
Frank CarterFrank Carter
so there isn't a way to have this requirement without creating a custom object?
alternatively when I go back from the record only to have the two data input fields filled with the last search so user have to click search?

Thanks
Abdul KhatriAbdul Khatri
At least I don't see any other way except what I propose?

That will help you to auto fill those two dates with calling the search at the time of page load. It may also help you in future in case if you user to extend search saving capability.