3

I am using standardsetcontroller for pagination. But it's not working properly. It's showing previous, next buttons correctly but records showing all the records, not shown what given in set.pageSize limit. Page:

<apex:pageBlock id="details">
    <apex:pageBlockButtons >
        <div align="right">
            <apex:commandLink action="{!previous}"  rendered="{!hasPrevious}" >Previous</apex:commandlink> &nbsp;&nbsp;
            <apex:commandLink action="{!next}" rendered="{!hasNext}">Next</apex:commandlink>
        </div>
    </apex:pageBlockButtons>
    <apex:pageBlockSection columns="1">
        <apex:pageBlockTable value="{!lstIssue}" var="issue">
            <apex:column headervalue="Action">
                <apex:outputLink value="{!URLFOR($Action.ADI_Issue__c.Edit,issue.Id)}">Edit</apex:outputLink>                                                                 
            </apex:column> 
            <apex:column headervalue="Name">
                <apex:outputLink value="{!URLFOR($Action.ADI_Issue__c.View,issue.Id)}">{!issue.Name}</apex:outputLink>
            </apex:column>
            <apex:column headervalue="Record Type" value="{!issue.RecordType.Name}"/>
            <apex:column headervalue="Project" value="{!issue.Project__r.Name}"/>
            <apex:column headerValue="Business Unit" value="{!issue.Business_Unit__c}"/>
            <apex:column headerValue="Status" value="{!issue.Status__c}"/>
            <apex:column headervalue="Requested Resolution Date" value="{!issue.Requested_Resolution_Date__c}"/>
            <apex:column headervalue="Assigned To" value="{!issue.Assigned_To__c}"/>
        </apex:pageBlockTable>
    </apex:pageBlockSection>
</apex:pageBlock>

Controller:

public with sharing class ADI_IssueHomeController{
    public ApexPages.StandardSetController con {
        get;
        set;
    }
    public  ADI_IssueHomeController() {  
        getIssueList();
    }
    public void getIssueList(){
        string strQuery1 = 'select id,name,Issue_Description__c,Business_Unit__c,Status__c,Requested_Resolution_Date__c,Assigned_To__c,Assigned_To__r.Name,RecordType.Name,Project__r.Name from ADI_Issue__c order by LastModifiedDate DESC';
        lstIssue=Database.query(strQuery1);
        Con = new ApexPages.StandardSetController(lstIssue);
        con.setPageSize(15);
    }
    public Boolean hasNext {
        get { return con.getHasNext(); }
        set;
    }
    public Boolean hasPrevious {
        get { return con.getHasPrevious(); }
        set;
    }
    public void previous() { 
        this.con.previous();
    }
    public void next() {
        this.con.next();
    }
}
1

The problem is you are querying the data and assigning to the list directly and referencing the list in your visualforce page. Here no where the standardsetcontroller came into picture.

So declaration of lstIssue should be like

List<ADI_Issue__c> lstIssue {
    get {
        return con.getRecords();
    }
    set;
}

and just comment this line

//lstIssue=Database.query(strQuery1);

You will be able to see only 15 records.

Hope it helps.

| improve this answer | |

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.