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
PuranKishorePuranKishore 

In Command Link how to create Buttons

 when we r in first page i must find only next, last pages in last page i must find only previous and first page

Best Answer chosen by Admin (Salesforce Developers) 
asish1989asish1989

Hi

I mean you want multi page navigation,if so then please refer I am sharing some code which will help you.

You can do it in a different panel, All panel will be in a single page, You will navigate from panel to panel , It will seems like navigating from page to page . Suppose there are three pages then you need to declare 3 panels.

      1-ist panle will only contain NEXT button 

      2-2nd will contain both PREV and NEXT button 

      3- 3rd will contain only PREV 

 

<apex:page controller="DesignController">
<script>
     function confirmBack(tagnew) {
        CallApexBackMethod(tagnew);
     }
    function confirmNext(tag) {
             CallApexMethod(tag);
    }   
  </script>
<apex:form>
  


   <apex:actionFunction name="CallApexMethod" action="{!next}" oncomplete="" reRender="thirdpanel,secondpanel,panel" status="myStatus">
        
        <apex:param name="tag" value="" />
    </apex:actionFunction>
    
    <apex:actionFunction name="CallApexBackMethod" action="{!back}" oncomplete="" reRender="secondpanel,panel" status="myStatus" immediate="true">
        
        <apex:param name="tagnew" value="" />
    </apex:actionFunction>
   <apex:pageBlock mode="edit" >
            <apex:outputPanel id="panel">
                <apex:pageBlockSection columns="1" rendered="{!visible = 'false'}">
                 // some of field are there 
                
                    <apex:commandButton  value="Next"  id="test2" onclick="return confirmNext('First')" immediate="true" reRender="secondpanel,panel" / >
</apex:pageBlockSection>
</apex:outputPanel>

<!--second panel-->
<apex:outputPanel id="secondpanel">
             <apex:outputPanel rendered="{!visible=='step1'}">
            
            <apex:pageBlockSection id="newsection"  columns="1">

           //your field....
        <apex:commandButton value="PREV"  onclick="return confirmBack('First')" immediate="true"  reRender="secondpanel,panel"/>
                           <apex:commandButton value="Next"  onclick="return confirmNext('Second')" immediate="true"  reRender="secondpanel,panel" />

</apex:pageBlockSection>
</apex:outputPanel>
</apex:outputPanel>
<!--THIRD PANEL-->

<apex:outputPanel id="thirdpanel">
           <apex:outputPanel rendered="{!visible=='step2'}" >
<apex:commandButton value="PREV" styleClass="backButton" onclick="return confirmBack('Second')" immediate="true"  reRender="thirdpanel,secondpanel,panel"/>
</apex:pageBlockSection>
</apex:outputPanel>
</apex:outputPanel>
</apex:pageBlock>
</apex:form> </apex:page>

 MY controller is 

public PageReference next(){
         
         //getting parameter value from page.
         visible = ApexPages.currentPage().getParameters().get('tag'); 
         System.debug('##### I am in first panel###');
         System.debug('##### I am in first panel###'+visible);
         
         //to know If this is first panel or not on next button
         if(visible =='First'){
             visible = 'step1';
             
         } 
         
         //second panel on next button 
         else if(visible =='Second'){
             visible = 'step2';
         }
       else visible = null;
   return null;
}

public PageReference back(){
         visible = ApexPages.currentPage().getParameters().get('tagnew');
         
         //second panel on back button
         if(visible =='First'){
             visible = 'false';
         }  
         
         //Third panel on back button
         else if(visible =='Second'){
             visible = 'step1';
         }
     else visible = null;
     return null;
}

 Did this post answers your question , If so please mark it as solved and hit kudos icon to make it as useful post.

 

 

Thanks