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
Stephen Eller 6Stephen Eller 6 

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.
 
Best Answer chosen by Stephen Eller 6
Stephen Eller 6Stephen Eller 6
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.

All Answers

Gaurav Srivastava_SDFCGaurav Srivastava_SDFC
Is the class is declared as without sharing??
Stephen Eller 6Stephen Eller 6
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.
This was selected as the best answer