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
bappabappa 

how to return to next set of records from standardSet Controller save method?

I am using StandardSetController in a custom Opportunity List view vf  page.The page works fine...also the navigation buttons like next,previous etc.Now I have set the pageSize to 5, when user clicks on next button it shows the next set of 5 record, if user clicks save now then the page is being redirected to the first 5 set of records page.I would like to redirect the page to next set of 5 records. How would I achieve that? I have overridden the standard save method the code snippet is below:
 
public PageReference doSave(){   
    
    PageReference p;  
    try{
    p =  this.controller.save();
    
    if(p != null){

        if(controller.getPageNumber() == 1){
        pg = new PageReference('/apex/OppListViewSorted');
        }
        else if(controller.getPageNumber() == 2){
                
        }
        ApexPages.addmessage(new ApexPages.message(ApexPages.severity.CONFIRM, 'Records saved successfully!!'));
        
        //}  
    }
    }catch(Exception exx){
        ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, 'An error occured on the page.Please try again reloading the page.'));
    }
    return pg;    
    }
and VF is :
 
<apex:page standardController="Opportunity" recordSetVar="Opportunities" tabStyle="Opportunity" sidebar="false" extensions="OppListControllerSorting" >
    <style>
        div.hideCurrDate span.dateInput span.dateFormat{
           display:none;
        }   
        
    </style> 


    <apex:stylesheet value="{!URLFOR($Resource.Spinner, 'spinner.css')}"/>
    <apex:includeScript value="{!URLFOR($Resource.Spinner, 'jquery.min.js')}"/>
    <apex:includeScript value="{!URLFOR($Resource.Spinner, 'spinner.js')}"/>
    <div class="splashStatus" id="splashDiv">
    <div class="circle"><img src="{!URLFOR($Resource.Spinner, 'spinner.gif')}"/></div>
    <div class="txt">Please Wait. Loading...</div>
    </div>
    <body>  
    <apex:form id="theForm" >
        
        <apex:pageBlock id="thePageblock" >
            <apex:pageMessages />           

            <apex:pageBlockButtons location="bottom" id="paginationButtons" >
                <apex:commandButton value="First" action="{!doFirst}" disabled="{!!HasPrevious}" />
                &nbsp;&nbsp;
                <apex:commandButton value="Previous" action="{!doPrevious}" disabled="{!!HasPrevious}" />
                &nbsp;&nbsp;
                <apex:commandButton value="Next" action="{!doNext}" disabled="{!!hasnext}" />
                &nbsp;&nbsp;
                <apex:commandButton value="Last" action="{!doLast}" disabled="{!!hasnext}" />
            </apex:pageBlockButtons>
            
            <apex:pageBlockButtons location="top" >                         
            <apex:outputLabel value="Select View:" id="theOutputLabel"/>       
            <apex:actionStatus id="splashStatus" onstart="startSplash();" onstop="endSplash();" />
            
            <apex:selectList value="{!filterId}" size="1">                 
                <apex:actionSupport event="onchange" rerender="thePageblock" status="splashStatus" action="{!changeListView}"/>
                <apex:selectOptions value="{!OpportunityExistingViews}"/>                                      
            </apex:selectList> 
            
            <apex:commandButton value="Save" action="{!doSave}"/>
            <apex:commandButton value="Cancel" action="{!doCancel}"/>
            </apex:pageBlockButtons>
            
            <apex:pageBlockTable value="{!Opportunities}" var="opp" id="list" >           

                <td><apex:column headerValue="Account Name">
                <apex:outputLink value="/{!opp.Account.Id}">{!opp.Account.Name}</apex:outputLink>
                </apex:column></td>
                <td><apex:column headerValue="Opportunity Name">
                <apex:facet name="header">
                <apex:commandLink action="{!ViewData}" value="Opportunity Name{!IF(sortExpression=='Name',IF(sortDirection='ASC','▲','▼'),'')}" status="splashStatus" onmouseover="showHelp()">
                    <apex:param value="Name" name="column" assignTo="{!sortExpression}" ></apex:param>
                </apex:commandLink>
                </apex:facet>
                <apex:outputLink value="/{!opp.id}">{!opp.Name}</apex:outputLink>
                </apex:column></td>
                <apex:column headerValue="Stage" >
                <apex:actionRegion >                
                    <apex:inputField value="{!opp.stageName}" style="width:90px">
                        <apex:actionSupport event="onchange" action="{!changeStageName}" reRender="probabilityInput" status="PStatus" />
                        <!-- <apex:param value="{!opp.stageName}" assignTo="{!selectedOppStage}"/> -->
                    </apex:inputfield>                 
                </apex:actionRegion> 
                </apex:column> 
                          
                <td ><apex:column headerValue="P(%)" id="probability"> 
                    <apex:actionStatus startText="Loading.." id="PStatus" />                 
                    <apex:inputField value="{!opp.Probability}" style="text-align:center;width:50px" id="probabilityInput"/>
                </apex:column>
                </td>
                <td><apex:column headerValue="Excl." >
                    <apex:inputField value="{!opp.Exclude_From_Forecast__c}" style="width:30px"/>
                </apex:column></td>
                <td ><apex:column headerValue="W/Amount" >
                    <apex:inputField value="{!opp.ExpectedRevenue}" style="text-align:right;width:60px" />
                </apex:column>
                </td>
                <apex:column headerValue="PO Date">
                <apex:facet name="header">
                <apex:commandLink action="{!ViewData}" value="PO Date{!IF(sortExpression=='PO Date',IF(sortDirection='ASC','▲','▼'),'')}" status="splashStatus" onmouseover="showHelp()" >
                    <apex:param value="PO Date" name="column" assignTo="{!sortExpression}" ></apex:param>
                </apex:commandLink>
                </apex:facet>
                <div class="hideCurrDate">
                    <apex:inputField value="{!opp.closeDate}" />
                </div>
                </apex:column>                
                <apex:column headerValue="D2Inv">
                    <apex:inputField value="{!opp.Days_to_Invoice__c}" style="text-align:center;width:30px"/>
                </apex:column>
                <apex:column headerValue="Invoice date">
                <div class="hideCurrDate">    
                    <apex:inputField value="{!opp.Invoice_Date__c}" style="width:70px"/>
                </div>    
                </apex:column>
                <apex:column headerValue="Access">
                    <apex:inputField value="{!opp.Access__c}" style="text-align:right;width:60px"/>
                </apex:column> 
                <apex:column headerValue="Video">
                    <apex:inputField value="{!opp.Video__c}" style="text-align:right;width:60px"/>
                </apex:column>   
                <apex:column headerValue="Fire">
                    <apex:inputField value="{!opp.Fire__c}" style="text-align:right;width:60px"/>
                </apex:column> 
                <apex:column headerValue="Intrusion">
                    <apex:inputField value="{!opp.Intrusion__c}" style="text-align:right;width:60px"/>
                </apex:column>   
                <apex:column headerValue="Fiber">
                    <apex:inputField value="{!opp.Fiber__c}" style="text-align:right;width:60px"/>
                </apex:column>        
                <apex:column headerValue="Key Mgmt">
                    <apex:inputField value="{!opp.Key_Management__c}" style="text-align:right;width:60px"/>
                </apex:column>
                <apex:column headerValue="Services">
                    <apex:inputField value="{!opp.Services__c}" style="text-align:right;width:60px"/>
                </apex:column>
                
                <apex:column headerValue="Other">
                    <apex:inputField value="{!opp.Other__c}" style="text-align:right;width:60px"/>
                </apex:column>
               <!-- <apex:column headerValue="Fire D&A">
                    <apex:inputField value="{!opp.Fire_D_A__c}" style="width:60px"/>
                </apex:column>  -->
                <!-- <apex:column headerValue="FireD&A HighHazards">
                    <apex:inputField value="{!opp.Fire_D_A_High_Hazards__c}" style="width:60px"/>
                </apex:column> -->
   
                <!-- <apex:column headerValue="Suppression">
                    <apex:inputField value="{!opp.Suppression__c}" style="width:60px"/>
                </apex:column>  --> 

            </apex:pageBlockTable> 
           
        </apex:pageBlock>
    </apex:form>
    </body>
    <div class="lightbox"></div>
</apex:page>


 
Best Answer chosen by bappa
RamuRamu (Salesforce Developers) 
The following post has the exact same issue discussion and a solution. Please try out the solution explained in that

https://developer.salesforce.com/forums/ForumsMain?id=906F000000096pCIAQ