0

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 {
                get{
                    if(setCon == null){
                        size = 10;
                        string queryString = 'Select id, name, phone, website, Active__c from Account';
                        setCon = new ApexPages.StandardSetController(Database.getQueryLocator(queryString));
                        setCon.setPageSize(size);
                        noOfRecords = setCon.getResultSize();
                    }
                    return setCon;
                }set;
            }
            Public List<Account> getAccounts(){
                List<Account> accList = new List<Account>();
                for(Account a : (List<Account>)setCon.getRecords())
                    accList.add(a);
                return accList;
            }
            public pageReference refresh() {
                setCon = null;
                getAccounts();
                setCon.setPageNumber(1);
                return null;
            }
            public DataTableEditRemoveController() {
               //load account data into our DataTable
               LoadData();
            }
            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) {
                    return;
                }
                // find the account record within the collection
                Account tobeDeleted = null;
                for(Account a : accs)
                if (a.Id == SelectedAccountId) {
                    tobeDeleted = a;
                    break;
               }    
                //if account record found delete it
                if (tobeDeleted != null) {
                Delete tobeDeleted;
                }
                //refresh the data
                LoadData();
           }

        }

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>

            </apex:column>
            <!-- 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:pageBlockTable>
    </apex:pageBlock>
    <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:outputPanel>
            </apex:panelGrid>
<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}"/>
</apex:actionFunction>
</apex:form>
</apex:page>
1

Find out following useful link with proper example and code :

[http://www.infallibletechie.com/2013/01/pagination-using-apex-in-salesforce.html][1]

| 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.