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
Ap30Ap30 

Next and previous in Apex

Hello All,
In standard view we should see only one record at a time. On clicking next button, it should show another single record. Record shown first should not be there. I couldn't implement as i'm new to pagination concept.Please help.

<apex:page standardController="obj__c" extensions="contollername">
 <apex:form >
    <apex:pageBlock title="Student's Data">
  
           <apex:pageBlockTable value="{!listitem}"  var="sd">
            
          <apex:column value="{!sd.First_Name__c}"/>
          <apex:column value="{!sd.Last_Name__c}"/>
          <apex:column value="{!sd.Company__c}"/>
             
                        
            </apex:pageBlockTable>
            <apex:pageBlockButtons >
    <apex:commandButton action="{!previous}" value="Prev"/>
      <apex:commandButton action="{!next}" value="Next"/>
    </apex:pageBlockButtons>
           
       </apex:pageBlock>
   </apex:form>
</apex:page> 

======================
public class contollername
{
    public transient List<obj__c> listitem{get; set;}
    public Integer size {get; set;}

    public contollername(ApexPages.StandardController stdController) {

         size=1;
         setLists();
    }

    public void setLists()
    {
       listitem= [Select First_Name__c,Last_Name__c,Company__c From obj__c limit:size];
    }

   public void next()
   {
      
      setLists();
   }
   
   public void previous()
   {
      
      setLists();
   }
}
Best Answer chosen by Ap30
PriyaPriya (Salesforce Developers) 
Hi,
 

Check below example that matches your requirement :- 

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

Please mark as Best Answer so that it can help others in the future.

Regards,

Priya Ranjan


 

All Answers

PriyaPriya (Salesforce Developers) 
Hi,
 

Check below example that matches your requirement :- 

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

Please mark as Best Answer so that it can help others in the future.

Regards,

Priya Ranjan


 
This was selected as the best answer
Ap30Ap30
Thanks. It worked.