Search code examples
salesforceapexsoql

Salesforce Soql query is limited to first 150 rows in custom object


I am confused as to why a SOQL query against a custom object is only returning the first 150 rows when it should be returning up to the governor limit (50,000). Does anyone have any ideas why my query is being limited?

Here's my controller method:

@RemoteAction
public static List<Metro__c> getAllMetros(){
    String query = 'SELECT Id, Name, state__c FROM Metro__c ORDER BY Name';
    List<Metro__c> r = Database.query(query);
    System.debug('r='+r.size());
    return r;
}

When i look at the debug I see:

10:48:27:237 USER_DEBUG [54]|DEBUG|r=150

There are several thousand records in the Metro__c object. Any insight into this would be appreciated.


Solution

  • This was my issue. The problem was how i was getting data into the Metro Object. I was reaching the 150 SoQL queries per request limit and I did not realize all of the records were not present in the object. After changing how the records were inserted, it all works properly.