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
Nitish PisalNitish Pisal 

Want to retrieve more than 50,000 records using SOQL Select query

Trying to query lead object and retrieve list<leads> with more than 50,000 records 
SELECT Id, Name, Field1, Field2 FROM lead where Status = 'Eligible' ...........
Without using group by clause
Prashant Pandey07Prashant Pandey07
Hi Nitish,

You can not query directly more than 50,000 records..

You need to process the record in small Batch..e.g 2000..
 
global class transactionRecords implements Database.Batchable<sObject>{

    String query;

    global transactionRecords(){
        this.query = 'SELECT Id FROM Lead';
    }

    global Database.QueryLocator start(Database.BatchableContext BC){
        return Database.getQueryLocator(query);
    }

    global void execute(Database.BatchableContext BC, List<sObject> scope){
        ....YOUR CODE...
    }

    global void finish(Database.BatchableContext BC){
    }
}

--
Thanks,
Prashant​
Nitish PisalNitish Pisal
Thanks Prashant! how about using an OFFSET will that work ?