After clicking the buttons my pagination is not working !! Anyone please look into it

Controller class

        public class DataTableEditRemoveController {
    public List<Account> accs { get; set; }
            //used to get a hold of the account record selected for deletion
            public string SelectedAccountId { get; set; }
            Public Integer noOfRecords{get; set;}
            Public Integer size{get;set;}
            public ApexPages.StandardSetController setCon {
                    if(setCon == null){
                        size = 10;
                        string queryString = 'Select id, name, phone, website, Active__c from Account';
                        setCon = new ApexPages.StandardSetController(Database.getQueryLocator(queryString));
                        noOfRecords = setCon.getResultSize();
                    return setCon;
            Public List<Account> getAccounts(){
                List<Account> accList = new List<Account>();
                for(Account a : (List<Account>)setCon.getRecords())
                return accList;
            public pageReference refresh() {
                setCon = null;
                return null;
            public DataTableEditRemoveController() {
               //load account data into our DataTable
            private void LoadData() {
               accs = [Select id, name, phone, website, Active__c from Account];

            public void DeleteAccount(){
                // if for any reason we are missing the reference 
                if (SelectedAccountId == null) {
                // find the account record within the collection
                Account tobeDeleted = null;
                for(Account a : accs)
                if (a.Id == SelectedAccountId) {
                    tobeDeleted = a;
                //if account record found delete it
                if (tobeDeleted != null) {
                Delete tobeDeleted;
                //refresh the data


Visual Force Page

<apex:page controller="DataTableEditRemoveController" sidebar="false">
<apex:form id="form" >
<apex:pageBlock title="Accounts">
    <apex:pageMessages />
        <apex:pageBlockTable value="{!accs}" var="row">
            <apex:column >
            <!-- Editing a Record(In Salesforce for standard objects you can follow this 
                            format to get the URL for their edit page: /{RecordId}/e)
                            /{RecordId}/e?retURL={returnURL} -->   
                <apex:outputLink title="" value="/{!row.id}/e?retURL=/apex/{!$CurrentPage.Name}" style="font-weight:bold">Edit</apex:outputLink>&nbsp;|&nbsp;
                <a href="javascript:if (window.confirm('Are you sure?')) DeleteAccount('{!row.Id}');" style="font-weight:bold">Del</a>

            <!-- List of Records --> 
            <apex:column value="{!row.Name}"/>
            <apex:column value="{!row.Phone}"/>
            <apex:column value="{!row.Website}"/>
            <apex:column value="{!row.Active__c}"/>
    <apex:panelGrid columns="7">
                <apex:commandButton status="fetchStatus" reRender="pb" value="First" action="{!setCon.first}" disabled="{!!setCon.hasPrevious}" title="First Page"/>
                <apex:commandButton status="fetchStatus" reRender="pb" value="Previous" action="{!setCon.previous}" disabled="{!!setCon.hasPrevious}" title="Previous Page"/>
                <apex:commandButton status="fetchStatus" reRender="pb" value="Next" action="{!setCon.next}" disabled="{!!setCon.hasNext}" title="Next Page"/>
                <apex:commandButton status="fetchStatus" reRender="pb" value="Last" action="{!setCon.last}" disabled="{!!setCon.hasNext}" title="Last Page"/>
                <apex:outputText >{!(setCon.pageNumber * size)+1-size}-{!IF((setCon.pageNumber * size)>noOfRecords, noOfRecords,(setCon.pageNumber * size))} of {!noOfRecords}</apex:outputText>
                <apex:commandButton status="fetchStatus" reRender="pb" value="Refresh" action="{!refresh}" title="Refresh Page"/>
                <apex:outputPanel style="color:#4AA02C;font-weight:bold">
                    <apex:actionStatus id="fetchStatus" startText="Fetching..." stopText=""/>
<apex:actionFunction action="{!DeleteAccount}" name="DeleteAccount" reRender="form" >
   <!-- Deleting a Record --(param" tag to the actionFunction component which 
                            passes the Account ID to the controller and as soon as user 
                            clicks on the link.)--> 
    <apex:param name="accountid" value="" assignTo="{!SelectedAccountId}"/>

Find out following useful link with proper example and code :


| improve this answer | |
  • I also have lots of references but I dont know what is the problem with my code – Sohail BeyondVision Jan 8 '15 at 13:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.