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 

SELECT only returning 20 records

Hey all,


I am having an issue where a SELECT statement is only returning the first 20 records, despite the fact that I have not placed any limits on it. Is there a limit of 20 for what a SELECT can return?


If not, I can post my code to see if anyone can help me with why my query is being limited.





Select statement can return upto 10000 records, if its returning only 20.Probably the user running the code doesn't have access to all records


pls provide  more detail

Sure thing,


What I am doing is displaying an editable list of object instances. So logically, I need to query for those objects. That code that follows is the method that gets called in the constructor to find the items. I know there are 39 items that should be returned, but it always gets a max of 20:



Database.QueryLocator ql;
        ID modelDefId = ApexPages.currentPage().getParameters().get('ModelDefId');
        if(Filter == null || Filter == ''){
            if(searchText == null || searchText == ''){
            ql = Database.getQueryLocator(
                [select Name, Admin_Display_Name__c, Attribute_Type__c, Is_Required__c, Default_Checkbox_Value__c, Default_Number_Value__c, Default_Text_Value__c, Default_Text_Area_Value__c,  Auto_Update__c, Possible_Picklist_Values__c, Default_Currency_Value__c, Default_Date_Value__c, Default_Percent_Value__c , Default_Picklist_Value__c FROM Definition__c WHERE Model_Definition__c = :modelDefId]);



This Database.QueryLocator then gets used to build the list:



MySetCtrl = new ApexPages.StandardSetController(ql);
MyList = (Definition__c[])MyCtrl.getRecords();
System.Debug(logginglevel.DEBUG, MyList.size());

 That debug always reports that the element has a size of 20.


Does anyone know why I am not getting all the records? This occurs across all Model Definitions, which are the containers for these Definitions.



I am also facing the same can anyone look into this?



can you check any of three approach:

1: check how many records there for what you are passing in where clause.

2: use either with sharing keywords in controller or go to user profile n check for that object do you have view all permission.


hope this will help you if this is a solution please mark as accepted. 


Yes i have checked the three approaches none of them its satisfiying but i'm getting max of 20 records


<apex:page standardController="Account" recordSetVar="accounts" extensions="AccountPagination">
    <apex:pageBlock title="Viewing Contacts">
        <apex:form id="theForm">
            <apex:pageBlockSection >
                <apex:dataList value="{!accountPagination}" var="acct" type="1">
                    {!} </apex:dataList>
            <apex:panelGrid columns="2">
                <apex:commandLink action="{!previous}">Previous</apex:commandlink>
                <apex:commandLink action="{!next}">Next</apex:commandlink>


public class AccountPagination {

    // The constructor passes in the standard controller defined
    // in the markup below
    public AccountPagination(ApexPages.StandardSetController controller) {
    public ApexPages.StandardSetController contactRecords{
        get {
            if(contactRecords== null) {
                contactRecords= new ApexPages.StandardSetController(
                    Database.getQueryLocator([SELECT name FROM Account order by name]));
            return contactRecords;
        private set;
    public List<Account> accountPagination{
    return accountPagination;


Now suggest me



Okay i got it i didnt override the previous method and next method

Thank you.