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
hemant ghaturkar 12hemant ghaturkar 12 

how to get different id on pagination

Deepali KulshresthaDeepali Kulshrestha
Hi hemant,


You can get different IDs and display all records of a particular object on this code.

Please check below code:
Visualforce Page:-

<apex:page controller="Question">  
    <apex:form >  
        <apex:pageBlock id="details" title="Details">
            
            <apex:dataList value="{!Account}" var="acc" > 
                <apex:outputText value="{!acc.Id}" /> &nbsp;&nbsp; 
            <apex:outputText value="{!acc.Name}"/> 
                </apex:dataList>
        
        <apex:pageBlockButtons>
            <apex:commandButton value="First" rerender="details" action="{!beginning}" disabled="{!prev}"/>  
            <apex:commandButton value="Previous" rerender="details" action="{!previous}" disabled="{!prev}"/>  
            <apex:commandButton value="Next" rerender="details" action="{!next}" disabled="{!nxt}"/>  
            <apex:commandButton value="Last" rerender="details" action="{!end}" disabled="{!nxt}"/> 
        </apex:pageBlockButtons>
    </apex:pageBlock>
</apex:form>  
</apex:page>



Apex Class:-

public class Question{
    private integer totalRecords = 0;       
    private integer index = 0;  
    private integer blockSize = 10;           
      
    public Question() {  
        totalRecords = [select count() from Account limit 200];        
    }       
    public List<Account> getAccount() {  
        List<Account> accRecords = Database.Query('SELECT Id,Name FROM Account LIMIT : blockSize OFFSET :index');  
        System.debug('Values are ' + accRecords);  
        return accRecords;  
    }      
    public void beginning() {  
        index = 0;  
    }   
    public void previous() { 
        index = index - blockSize;  
    }  
    public void next() {  
        index = index + blockSize;  
    }  
    public void end() {  
        index = totalRecords - math.mod(totalRecords,blockSize);  
    }            
    public boolean getprev() {  
        if(index == 0)  
            return true;  
        else  
            return false;  
    }     
    public boolean getnxt() {  
        if((index + blockSize) > totalRecords)  
        return true;  
        else  
        return false;  
    }      
}


I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha
www.kdeepali.com