In the developer console query editor, if I enter the query
select lastmodifiedDate from foo__c order by lastmodifiedDate desc limit 1
it runs fine. But the moment I try do that same query inside of a controller, I get an Internal Server Error. Debug logs show
14:44:11.956 (103956172471)|SOQL_EXECUTE_BEGIN||Aggregations:0|select lastmodifiedDate from foo__c order by lastmodifiedDate desc limit 1 14:46:15.080 (227080647980)|FATAL_ERROR|Internal Salesforce.com Error 14:46:15.080 (227080675619)|CUMULATIVE_LIMIT_USAGE 14:46:15.080 (227080675619)|LIMIT_USAGE_FOR_NS|(default)| Number of SOQL queries: 4 out of 100 Number of query rows: 57 out of 50000 Number of SOSL queries: 0 out of 20 Number of DML statements: 0 out of 150 Number of DML rows: 0 out of 10000 Maximum CPU time: 100 out of 10000 Maximum heap size: 0 out of 6000000 Number of callouts: 0 out of 100 Number of Email Invocations: 0 out of 10 Number of future calls: 0 out of 50 Number of queueable jobs added to the queue: 0 out of 50 Number of Mobile Apex push calls: 0 out of 10
As you can see from the log above, it says the soql query takes over 2 minutes before returning the error. Why is my query failing inside a controller?