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
Shruti Suman MishraShruti Suman Mishra 

Can we use Database.QueryLocator() for List of SObjects?


I've a code where I need to write select queries for multiple objects, I understand that I can use Iterable<String> return type for Batch start method, but as I'm expecting huge output, can I use QueryLocator to pass list of Queries and bypass the Governer Limit?

global Database.QueryLocator start(Database.BatchableContext bc) {
     List<String> queries=new List<String>();
            String query1 = 'SELECT Id FROM Contact';
            String query2='SELECT Id FROM Account';
       return Database.getQueryLocator(queries);

Is there any other way to bypass governer limit?
Sumit Kumar Singh 9Sumit Kumar Singh 9
Hello Shruti Suman Mishra,

You can have chain of batces for such requirement.
In the  first batch you can process the contact records and in the finish method, you can call another batch which process the account records.

Hope this helps you.

Sumit Kumar Singh
Shruti Suman MishraShruti Suman Mishra
Yes Sumit,

I guess that's the only alternative to bypass limit. Thanks for your input.