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
Ajay GautamAjay Gautam 

Need Help: Have to have SOQL on VF page returning more than 200K records

Hey Experts,

Need suggestions about implementing a VF page (that has ReadOnly annotation = true).
Controller needs to deal with Really large data set with less SOQL filters to query, and then loop on based on Maps.
This situation is making us face the CPU time limit, where a LARGE portion of execution is in SOQL. Any suggestion to avoid this? Offset? Tuning?

Please advise. Thanks in advance!
 
Amit Chaudhary 8Amit Chaudhary 8
Hi AG101,

You can try below three option
1) Pagination http://amitsalesforce.blogspot.in/search/label/Pagination
2) Offset
https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_offset.htm
Considerations When Using OFFSET
->Here are a few points to consider when using OFFSET in your queries:
->The maximum offset is 2,000 rows. Requesting an offset greater than 2,000 will result in a NUMBER_OUTSIDE_VALID_RANGEerror.
OFFSET is intended to be used in a top-level query, and is not allowed in most sub-queries, so the following query is invalid and will return a MALFORMED_QUERY error:
http://salesforce.stackexchange.com/questions/42702/how-to-paginate-10000-records-soql-offset-and-standardsetcontroller-too-limit
http://sfdcgurukul.blogspot.in/2013/10/how-to-use-offset-in-soql-query.html
3) ReadOnly 
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_controller_readonly_context_pagelevel.htm
 
<apex:page controller="SummaryStatsController" readOnly="true">
    <p>Here is a statistic: {!veryLargeSummaryStat}</p>
</apex:page>

Normally, queries for a single Visualforce page request may not retrieve more than 50,000 rows. In read-only mode, this limit is relaxed to allow querying up to 1 million rows.

In addition to querying many more rows, the readOnly attribute also increases the maximum number of items in a collection that can be iterated over using components such as <apex:dataTable>, <apex:dataList>, and <apex:repeat>. This limit increased from1,000 items to 10,000.

Please let us know if this will help u

Thanks
Amit Chaudhary