Activity › Forums › Salesforce® Discussions › How to Fetch more than 50k records using SOQL in Salesforce?
Tagged: Dynamic SOQL, Fetch Records, Find Records, Salesforce Records, Salesforce SOQL, SOQL Injection, SOQL Query
-
How to Fetch more than 50k records using SOQL in Salesforce?
Posted by Saurabh on April 26, 2018 at 4:24 PMhow can we Fetch more than 50k records from SOQL?
Aman replied 8 years ago 3 Members · 2 Replies -
2 Replies
-
Hi saurabh,
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.
<apex:page controller=”SummaryStatsController” readOnly=”true”>
<p>Here is a statistic: {!veryLargeSummaryStat}</p>
</apex:page>The controller for this page is also simple, but illustrates how you can calculate summary statistics for display on a page:
public class SummaryStatsController
{
public Integer getVeryLargeSummaryStat()
{
Integer closedOpportunityStats =
[SELECT COUNT() FROM Opportunity WHERE Opportunity.IsClosed = true];
return closedOpportunityStats;
}
}Thanks.
- [adinserter block='9']
-
Hi Saurabh,
You should look at using Batch Apex to accomplish your goals.
You cannot retrieve more than 50,000 records your SOQL calls in a single context.
However, with Batch Apex your logic will be processed in chunks of anywhere from 1 to 200 records in a batch.
You’d need to modify your business logic to take the batching into account if necessary.
Thanks
Log In to reply.