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
DennoPDennoP 

I get the error "Inline query has too many rows for direct assignment, use FOR loop"

While I am trying to display a list of records in a data table I get the following message:

Inline query has too many rows for direct assignment, use FOR loop.

Can anyone tell me how could I amend the controller below to use the FOR loop to handle the result.

public List<Appointment__c> getVisits(){
   
   
    return [SELECT id, Assigned_To__c, Time_Band__c, Visit_Date__c, Visit_Type__c
            FROM Appointment__c
            WHERE Assigned_To__c = 'a0AR0000000UJBI'];
 }

Any help is appretiated.
mtbclimbermtbclimber
Your query is returning more than the maximum allowable number of items in a collection (1000). To avoid this you need to either add a limit clause to your query or if you are processing the result in apex you can chunk the processing. For the case of the latter, see "SOQL For Loop Formats" on page 49 of the Apex Language Reference.


DennoPDennoP
Thanks for the info.  I only needed to show about 200 records at the most so I added a limit as suggested.

Thanks for the help.
:manhappy: