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
Mohan Raj 33Mohan Raj 33 

How to solve this problem in apex controller class?

Hi, to all I am new in the extension controller here I try implement the function on the sorting to my visual force page but the sorting and pagination is not working together here(I already done the pagination only using the standard controller). So I check the developer console on my apex class it's provide the error on followingly in the image
User-added image
So I don't know how to clear this error so please help me to done this task.and my apex class is followingly,
public class AccountListViewController{
public List<Account> AccountsortList {get; set;}
public String SortingExpression = 'name';
public String DirectionOfSort = 'ASC';
public Integer NoOfRecords {get; set;}
public Integer Size{get; set;}

    public AccountListViewController(ApexPages.StandardSetController controller) {
        AccountsortList = new List<Account>();
        ApexPages.StandardSetController ssc = new ApexPages.StandardSetController(AccountsortList);
        
    }
    
    /*public Integer pageNumber {
        get {
        return ssc.getpageNumber();
        }
        set;
    }*/
    public String ExpressionSort {
        get {
            return SortingExpression;
        }
        set {
            If(value == SortingExpression) {
                DirectionOfSort = (DirectionOfSort == 'ASC')? 'DESC' : 'ASC';
            }
            else {
                DirectionOfSort = 'ASC';
                SortingExpression = value;
            }
        }
    
    }
    
    public String getDirectionOfSort() {
        If(SortingExpression == Null || SortingExpression == '') {
            return 'DESC';
        }
        else {
            return DirectionOfSort;
        }
    }
    
    public void setDirectionOfSort(String value) {
        DirectionOfSort = value;
    }
    
    public List<Account>getAccounts() {
        return AccountsortList;
    }
    
     public PageReference ViewData() {
        String FullSortExpression = SortingExpression + ' ' + DirectionOfSort;
        system.debug('SortingExpression:::::'+SortingExpression);
        system.debug(DirectionOfSort);
        
       String Queryitem = ' SELECT Id, Name, Phone, BillingState, Type, Owner.Name, Website FROM Account WHERE Account.Name != Null ORDER BY ' + FullSortExpression +' Limit 10';
       system.debug(Queryitem);
       
        AccountsortList = DataBase.query(Queryitem);
        system.debug(AccountsortList);
        return Null;
    }
}

For answer's thanks in advance.Thanks Mohan. 
Best Answer chosen by Mohan Raj 33
SrikanthKuruvaSrikanthKuruva
Well, you have to implement the Next Previous First and Last actions in your controller and rerender the AccountList OutputPanel

All Answers

SrikanthKuruvaSrikanthKuruva
did you use the rerender attribute in the vf page? post your vf page code to help you better
Mohan Raj 33Mohan Raj 33
@SrikanthKuruva thanks for the reply I am not using any rerender attribute for your ref my page is followingly,
<apex:page standardController="Account" recordSetVar="AccountsortList" action="{!ViewData}" extensions="AccountListViewController">

<apex:sectionHeader title="My Accounts" subtitle="Account List View"/>
    <apex:form >
        <apex:pageBlock >
          <apex:pageMessages id="error" />
          
                <apex:pageBlockTable value="{!AccountsortList}" var="t" rendered="{!NOT(ISNULL(AccountsortList))}" id="blocktable">
                                          
                        <apex:column >
                            <apex:facet name="header">   
                                <apex:commandLink action="{!ViewData}" value="Account Name{!IF(ExpressionSort=='name',IF(DirectionOfSort == 'ASC', '▼', '▲'),'')}">
                                    <apex:param value="name" name="column" assignTo="{!ExpressionSort}" ></apex:param>
                                </apex:commandLink>
                            </apex:facet>
                            <apex:outputLink value="/{!t.Id}" target="_blank">{!t.Name}</apex:outputLink>
                        </apex:column>
                        
                                                
                       <!-- <apex:column headerValue="BillingState/Province" value="{!t.BillingState}"/>---> 
                        <apex:column value="{!t.BillingState}">
                            <apex:facet name="header">
                                <apex:commandLink action="{!ViewData}" value="BillingState{!IF(ExpressionSort=='BillingState',IF(DirectionOfSort == 'ASC', '▼', '▲'),'')}">
                                    <apex:param value="BillingState" name="column" assignTo="{!ExpressionSort}"></apex:param>
                                </apex:commandLink>
                            </apex:facet>
                        </apex:column>
                        
                        <apex:column value="{!t.Phone}">
                            <apex:facet name="header">
                                <apex:commandLink action="{!ViewData}" value="Phone{!IF(ExpressionSort=='Phone',IF(DirectionOfSort == 'ASC', '▼', '▲'),'')}">
                                    <apex:param value="Phone" name="column" assignTo="{!ExpressionSort}"></apex:param>
                                </apex:commandLink>
                            </apex:facet>
                        </apex:column>
                        
                        <apex:column value="{!t.Type}">
                            <apex:facet name="header">
                                <apex:commandLink action="{!ViewData}" value="Type{!IF(ExpressionSort=='Type',IF(DirectionOfSort == 'ASC', '▼', '▲'),'')}">
                                    <apex:param value="Type" name="column" assignTo="{!ExpressionSort}"></apex:param>
                                </apex:commandLink>
                            </apex:facet>
                        </apex:column>
                        
                        <apex:column value="{!t.Owner.Name}">
                            <apex:facet name="header">
                                <apex:commandLink action="{!ViewData}" value="OwnerName{!IF(ExpressionSort=='Owner.Name',IF(DirectionOfSort == 'ASC', '▼', '▲'),'')}">
                                    <apex:param value="Owner.Name" name="column" assignTo="{!ExpressionSort}"></apex:param>
                                </apex:commandLink>
                            </apex:facet>
                        </apex:column>
                        
                        <apex:column value="{!t.Website}">
                            <apex:facet name="header">
                                <apex:commandLink action="{!ViewData}" value="Website{!IF(ExpressionSort=='website',IF(DirectionOfSort == 'ASC', '▼', '▲'),'')}">
                                    <apex:param value="Website" name="column" assignTo="{!ExpressionSort}"></apex:param>
                                </apex:commandLink>
                            </apex:facet>
                        </apex:column>
                                           
                       <!-- <apex:column headerValue="Account Owner Alias" value="{!t.Owner.Name}"/>--->
                       <!-- <apex:column headerValue="Website" value="{!t.Website}"/>---->
                   
                    <apex:inlineEditSupport event="onClick"/>
                   
                    
                </apex:pageBlockTable>
                
          <apex:panelGrid columns="7" id="buttons" >
           <!---<apex:pageBlockButtons>---->
                <apex:commandButton reRender="error,blocktable,buttons" action="{!Save}" value="Save"/>
                <apex:commandButton reRender="error,blocktable,buttons" action="{!Cancel}" value="Cancel"/>
                <apex:inputHidden />
                
                <apex:commandButton reRender="error,blocktable,buttons" disabled="{!!hasprevious}" action="{!First}" value="First"/>
                <apex:commandButton reRender="error,blocktable,buttons" disabled="{!!hasprevious}" action="{!Previous}" value="Previous"/>
                <apex:commandButton reRender="error,blocktable,buttons" disabled="{!!hasnext}" action="{!Next}" value="Next"/>
                <apex:commandButton reRender="error,blocktable,buttons" disabled="{!!hasnext}" action="{!Last}" value="Last"/>
           <!---</apex:pageBlockButtons>--->
          </apex:panelGrid>
          
           
        </apex:pageBlock>
    </apex:form>
</apex:page>

Thank you, Mohan
SrikanthKuruvaSrikanthKuruva
try putting your page block table in the output panel and rerender it in every header as below
<apex:outputPanel id="AccountsList">
    <apex:pageBlockTable value="{!AccountsortList}" var="t" rendered="{!NOT(ISNULL(AccountsortList))}" id="blocktable">
        <apex:commandLink action="{!ViewData}" value="Account Name{!IF(ExpressionSort=='name',IF(DirectionOfSort == 'ASC', '▼', '▲'),'')}" reRender="AccountsList">
            <apex:param value="name" name="column" assignTo="{!ExpressionSort}" ></apex:param>
        </apex:commandLink>
    ....
    ....
    </apex:pageBlockTable>
    </apex:outputPanel>

let me know how that goes
Mohan Raj 33Mohan Raj 33
@SrikanthKuruva Now also my pagination is not working with the sorting order sir, as my page,
<apex:page standardController="Account" recordSetVar="AccountsortList" action="{!ViewData}" extensions="AccountListViewController">

<apex:sectionHeader title="My Accounts" subtitle="Account List View"/>
    <apex:form >
        <apex:pageBlock >
          <apex:pageMessages id="error" />
          
                <apex:outputPanel id="AccountList">
                <apex:pageBlockTable value="{!AccountsortList}" var="t" rendered="{!NOT(ISNULL(AccountsortList))}" id="blocktable">
                                          
                        <apex:column >
                            <apex:facet name="header">   
                                <apex:commandLink action="{!ViewData}" value="Account Name{!IF(ExpressionSort=='name',IF(DirectionOfSort == 'ASC', '▼', '▲'),'')}" reRender="AccountList" >
                                    <apex:param value="name" name="column" assignTo="{!ExpressionSort}" ></apex:param>
                                </apex:commandLink>
                            </apex:facet>
                            <apex:outputLink value="/{!t.Id}" target="_blank">{!t.Name}</apex:outputLink>
                        </apex:column>
                        
                                                
                    <!--<apex:column headerValue="BillingState/Province" value="{!t.BillingState}"/>---> 
                       
                        <apex:column value="{!t.BillingState}">
                            <apex:facet name="header">
                                <apex:commandLink action="{!ViewData}" value="BillingState{!IF(ExpressionSort=='BillingState',IF(DirectionOfSort == 'ASC', '▼', '▲'),'')}" reRender="AccountList">
                                    <apex:param value="BillingState" name="column" assignTo="{!ExpressionSort}"></apex:param>
                                </apex:commandLink>
                            </apex:facet>
                        </apex:column>
                        
                        <apex:column value="{!t.Phone}">
                            <apex:facet name="header">
                                <apex:commandLink action="{!ViewData}" value="Phone{!IF(ExpressionSort=='Phone',IF(DirectionOfSort == 'ASC', '▼', '▲'),'')}" reRender="AccountList">
                                    <apex:param value="Phone" name="column" assignTo="{!ExpressionSort}"></apex:param>
                                </apex:commandLink>
                            </apex:facet>
                        </apex:column>
                        
                        <apex:column value="{!t.Type}">
                            <apex:facet name="header">
                                <apex:commandLink action="{!ViewData}" value="Type{!IF(ExpressionSort=='Type',IF(DirectionOfSort == 'ASC', '▼', '▲'),'')}" reRender="AccountList">
                                    <apex:param value="Type" name="column" assignTo="{!ExpressionSort}"></apex:param>
                                </apex:commandLink>
                            </apex:facet>
                        </apex:column>
                        
                        <apex:column value="{!t.Owner.Name}">
                            <apex:facet name="header">
                                <apex:commandLink action="{!ViewData}" value="OwnerName{!IF(ExpressionSort=='Owner.Name',IF(DirectionOfSort == 'ASC', '▼', '▲'),'')}" reRender="AccountList">
                                    <apex:param value="Owner.Name" name="column" assignTo="{!ExpressionSort}"></apex:param>
                                </apex:commandLink>
                            </apex:facet>
                        </apex:column>
                        
                        <apex:column value="{!t.Website}">
                            <apex:facet name="header">
                                <apex:commandLink action="{!ViewData}" value="Website{!IF(ExpressionSort=='website',IF(DirectionOfSort == 'ASC', '▼', '▲'),'')}" reRender="AccountList">
                                    <apex:param value="Website" name="column" assignTo="{!ExpressionSort}"></apex:param>
                                </apex:commandLink>
                            </apex:facet>
                        </apex:column>
                                           
                       <!-- <apex:column headerValue="Account Owner Alias" value="{!t.Owner.Name}"/>--->
                       <!-- <apex:column headerValue="Website" value="{!t.Website}"/>---->
                   
                    <apex:inlineEditSupport event="onClick"/>
                   
                    
                </apex:pageBlockTable>
                </apex:outputPanel>
                
          <apex:panelGrid columns="7" id="buttons" >
           <!---<apex:pageBlockButtons>---->
                <apex:commandButton reRender="error,blocktable,buttons" action="{!Save}" value="Save"/>
                <apex:commandButton reRender="error,blocktable,buttons" action="{!Cancel}" value="Cancel"/>
                <apex:inputHidden />
                
                <apex:commandButton reRender="error,blocktable,buttons" disabled="{!!hasprevious}" action="{!First}" value="First"/>
                <apex:commandButton reRender="error,blocktable,buttons" disabled="{!!hasprevious}" action="{!Previous}" value="Previous"/>
                <apex:commandButton reRender="error,blocktable,buttons" disabled="{!!hasnext}" action="{!Next}" value="Next"/>
                <apex:commandButton reRender="error,blocktable,buttons" disabled="{!!hasnext}" action="{!Last}" value="Last"/>
           <!---</apex:pageBlockButtons>--->
          </apex:panelGrid>
          
           
        </apex:pageBlock>
    </apex:form>
</apex:page>

 
SrikanthKuruvaSrikanthKuruva
check the debug logs when you click on the column header and check if the below debug line is showing the AccountsList correctly

system.debug(AccountsortList); 
 
Mohan Raj 33Mohan Raj 33
@SrikanthKuruva same error repeated in the my question image like error:Line: 34, Column: 31
Constructor not defined: [AccountListViewController].<Constructor>().
SrikanthKuruvaSrikanthKuruva
Well, you have to implement the Next Previous First and Last actions in your controller and rerender the AccountList OutputPanel
This was selected as the best answer
Mohan Raj 33Mohan Raj 33
@SrikanthKuruva Sir, Actually it's(First,Previous,Last,Next) I done in the only the visual force page by using the standard controller then I implement the this AccountListViewController to the extension for the sorting purpose as based on initial time it's worked the previous,next,last,first buttons are worked perfectly now only it's not working Can you please change my code for the logic to the working thus buttons with sorting functionality sir acttually  I am new guy to the salesforce and the standard controller field please help me sir to done this task sir or suggest some pages like as i do sir please.