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
Mahesh Reddy 72Mahesh Reddy 72 

System.QueryException: unexpected token: By

i facing this type of error in my class,
System.QueryException: unexpected token: By 
Class.PaginatoinExampleProgramForJob.__sfdc_setCon: line 9, column 1
Class.PaginatoinExampleProgramForJob.getAccounts: line 18, column 1

And under this is my class
public class PaginatoinExampleProgramForJob {
    Public integer noOfRecords{set; get;}
    public integer size{set; get;}
    public Apexpages.StandardSetController setCon{
        get{
            if(setCon == null){
            size=10;
            string query='SELECT Name, Type, Billingcity, Billingstate, BillingCountry FROM Account Ordered By Name';
            setCon = new ApexPages.StandardSetController(Database.getQueryLocator(query));
                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;
}
}
 
Amit Chaudhary 8Amit Chaudhary 8
in your SOQL it should be order by not orderd by

Please update your code like below
public class PaginatoinExampleProgramForJob {
    Public integer noOfRecords{set; get;}
    public integer size{set; get;}
    public Apexpages.StandardSetController setCon{
        get{
            if(setCon == null){
            size=10;
            string query='SELECT Name, Type, Billingcity, Billingstate, BillingCountry FROM Account Order By Name';
            setCon = new ApexPages.StandardSetController(Database.getQueryLocator(query));
                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;
}
}

Let us know if this will help you