SOQL Scenario- 2

Create pagination using Soql 

public class SoqlQuery2 {
    public list<Account> acc{set;get;}
    
    public SoqlQuery2 ()
    {
        acc=new list<Account>();
    }
    integer count=0;
    public void prev(){
        if(count>10)
            count=count-10;
        else
            count=0;
    }
    public void next(){
        count=count+10;
    }
    public List<Account> getData(){
        acc=[select id, name from account limit 10 offset: count];
        return acc;
    }
}

<apex:page controller="SoqlQuery2">
    <apex:form >
    <apex:pageBlock >
        <apex:pageBlockSection >
            <apex:pageBlockTable value="{!Data}" var="a">
                    <apex:column headerValue="Name" value="{!a.name}" />
                </apex:pageBlockTable><br/>
                <apex:commandButton value="<<< prev" action="{!prev}" />
                <apex:commandButton value="Next >>>" action="{!next}" />
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>



Comments

Popular posts from this blog

Page Layouts

SOQL Scenario-1