How to process more than 25 batches of 2000 records?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
1
down vote

favorite












I am trying to chunk the results of a query of mine, but I am noticing the batches stop after 50,000 records (25 batches of 2000 records). I read iterable has a limit of 50,000 but I thought that was 50,000 records per batch.



What are my options for being able to query and process all of my case records when recordtype 000 has over 50,000 records and record type 111 has over 50,000 records?



Execute Anonymous:



Database.executeBatch(new batchClassExample(), 2000);



Batch Class:



global class batchClassExample implements Database.Batchable < Case > 

List < string > exampleRecordTypeIds = new List < string > ();


global batchClassExample()
string exampleRecordTypeIdString = '000XXX000XXX, 111XXX111XXX';
exampleRecordTypeIdString = exampleRecordTypeIdString.deleteWhitespace();
exampleRecordTypeIds = exampleRecordTypeIdString.split(',');


global Iterable < Case > start(Database.BatchableContext BC)
Integer count = Limits.getLimitQueryRows() - Limits.getQueryRows();
return [select Id, Owner.Id from case where RecordType.Id = :exampleRecordTypeIds LIMIT: count
];


global void execute(Database.BatchableContext BC,
List < Case > scope)

for (integer s = 0; s < scope.size(); s++)
system.debug(scope[s]);





global void finish(Database.BatchableContext BC)









share|improve this question


























    up vote
    1
    down vote

    favorite












    I am trying to chunk the results of a query of mine, but I am noticing the batches stop after 50,000 records (25 batches of 2000 records). I read iterable has a limit of 50,000 but I thought that was 50,000 records per batch.



    What are my options for being able to query and process all of my case records when recordtype 000 has over 50,000 records and record type 111 has over 50,000 records?



    Execute Anonymous:



    Database.executeBatch(new batchClassExample(), 2000);



    Batch Class:



    global class batchClassExample implements Database.Batchable < Case > 

    List < string > exampleRecordTypeIds = new List < string > ();


    global batchClassExample()
    string exampleRecordTypeIdString = '000XXX000XXX, 111XXX111XXX';
    exampleRecordTypeIdString = exampleRecordTypeIdString.deleteWhitespace();
    exampleRecordTypeIds = exampleRecordTypeIdString.split(',');


    global Iterable < Case > start(Database.BatchableContext BC)
    Integer count = Limits.getLimitQueryRows() - Limits.getQueryRows();
    return [select Id, Owner.Id from case where RecordType.Id = :exampleRecordTypeIds LIMIT: count
    ];


    global void execute(Database.BatchableContext BC,
    List < Case > scope)

    for (integer s = 0; s < scope.size(); s++)
    system.debug(scope[s]);





    global void finish(Database.BatchableContext BC)









    share|improve this question






















      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I am trying to chunk the results of a query of mine, but I am noticing the batches stop after 50,000 records (25 batches of 2000 records). I read iterable has a limit of 50,000 but I thought that was 50,000 records per batch.



      What are my options for being able to query and process all of my case records when recordtype 000 has over 50,000 records and record type 111 has over 50,000 records?



      Execute Anonymous:



      Database.executeBatch(new batchClassExample(), 2000);



      Batch Class:



      global class batchClassExample implements Database.Batchable < Case > 

      List < string > exampleRecordTypeIds = new List < string > ();


      global batchClassExample()
      string exampleRecordTypeIdString = '000XXX000XXX, 111XXX111XXX';
      exampleRecordTypeIdString = exampleRecordTypeIdString.deleteWhitespace();
      exampleRecordTypeIds = exampleRecordTypeIdString.split(',');


      global Iterable < Case > start(Database.BatchableContext BC)
      Integer count = Limits.getLimitQueryRows() - Limits.getQueryRows();
      return [select Id, Owner.Id from case where RecordType.Id = :exampleRecordTypeIds LIMIT: count
      ];


      global void execute(Database.BatchableContext BC,
      List < Case > scope)

      for (integer s = 0; s < scope.size(); s++)
      system.debug(scope[s]);





      global void finish(Database.BatchableContext BC)









      share|improve this question












      I am trying to chunk the results of a query of mine, but I am noticing the batches stop after 50,000 records (25 batches of 2000 records). I read iterable has a limit of 50,000 but I thought that was 50,000 records per batch.



      What are my options for being able to query and process all of my case records when recordtype 000 has over 50,000 records and record type 111 has over 50,000 records?



      Execute Anonymous:



      Database.executeBatch(new batchClassExample(), 2000);



      Batch Class:



      global class batchClassExample implements Database.Batchable < Case > 

      List < string > exampleRecordTypeIds = new List < string > ();


      global batchClassExample()
      string exampleRecordTypeIdString = '000XXX000XXX, 111XXX111XXX';
      exampleRecordTypeIdString = exampleRecordTypeIdString.deleteWhitespace();
      exampleRecordTypeIds = exampleRecordTypeIdString.split(',');


      global Iterable < Case > start(Database.BatchableContext BC)
      Integer count = Limits.getLimitQueryRows() - Limits.getQueryRows();
      return [select Id, Owner.Id from case where RecordType.Id = :exampleRecordTypeIds LIMIT: count
      ];


      global void execute(Database.BatchableContext BC,
      List < Case > scope)

      for (integer s = 0; s < scope.size(); s++)
      system.debug(scope[s]);





      global void finish(Database.BatchableContext BC)











      share|improve this question











      share|improve this question




      share|improve this question










      asked Aug 22 at 21:23









      S.B.

      3069




      3069




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          4
          down vote



          accepted










          Your start method is limited to 50,000 SOQL rows, except for your Database.QueryLocator, if you choose to use one. To get past this limit, use a Database.QueryLocator:



           return (Iterable<Case>)Database.getQueryLocator([
          select Id, Owner.Id from case where RecordType.Id = :exampleRecordTypeIds
          ]);





          share|improve this answer



























            up vote
            3
            down vote













            A batch can process up to 50 million records. Based on documentation
            , I think you may want to change your code in the following ways:



            1. Create a global string variable, call it "queryString" for example - which holds the query for both recordtypes (I.E 'Where RecordTypeId IN: recordTypeIds')


            2. Change the start() method to return type DataBase.queryLocator, and within the start method call Database.queryLocator(queryString).






            share|improve this answer




















              Your Answer







              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "459"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              convertImagesToLinks: false,
              noModals: false,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              bindNavPrevention: true,
              postfix: "",
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













               

              draft saved


              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f229818%2fhow-to-process-more-than-25-batches-of-2000-records%23new-answer', 'question_page');

              );

              Post as a guest






























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              4
              down vote



              accepted










              Your start method is limited to 50,000 SOQL rows, except for your Database.QueryLocator, if you choose to use one. To get past this limit, use a Database.QueryLocator:



               return (Iterable<Case>)Database.getQueryLocator([
              select Id, Owner.Id from case where RecordType.Id = :exampleRecordTypeIds
              ]);





              share|improve this answer
























                up vote
                4
                down vote



                accepted










                Your start method is limited to 50,000 SOQL rows, except for your Database.QueryLocator, if you choose to use one. To get past this limit, use a Database.QueryLocator:



                 return (Iterable<Case>)Database.getQueryLocator([
                select Id, Owner.Id from case where RecordType.Id = :exampleRecordTypeIds
                ]);





                share|improve this answer






















                  up vote
                  4
                  down vote



                  accepted







                  up vote
                  4
                  down vote



                  accepted






                  Your start method is limited to 50,000 SOQL rows, except for your Database.QueryLocator, if you choose to use one. To get past this limit, use a Database.QueryLocator:



                   return (Iterable<Case>)Database.getQueryLocator([
                  select Id, Owner.Id from case where RecordType.Id = :exampleRecordTypeIds
                  ]);





                  share|improve this answer












                  Your start method is limited to 50,000 SOQL rows, except for your Database.QueryLocator, if you choose to use one. To get past this limit, use a Database.QueryLocator:



                   return (Iterable<Case>)Database.getQueryLocator([
                  select Id, Owner.Id from case where RecordType.Id = :exampleRecordTypeIds
                  ]);






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Aug 22 at 21:31









                  sfdcfox

                  225k10171384




                  225k10171384






















                      up vote
                      3
                      down vote













                      A batch can process up to 50 million records. Based on documentation
                      , I think you may want to change your code in the following ways:



                      1. Create a global string variable, call it "queryString" for example - which holds the query for both recordtypes (I.E 'Where RecordTypeId IN: recordTypeIds')


                      2. Change the start() method to return type DataBase.queryLocator, and within the start method call Database.queryLocator(queryString).






                      share|improve this answer
























                        up vote
                        3
                        down vote













                        A batch can process up to 50 million records. Based on documentation
                        , I think you may want to change your code in the following ways:



                        1. Create a global string variable, call it "queryString" for example - which holds the query for both recordtypes (I.E 'Where RecordTypeId IN: recordTypeIds')


                        2. Change the start() method to return type DataBase.queryLocator, and within the start method call Database.queryLocator(queryString).






                        share|improve this answer






















                          up vote
                          3
                          down vote










                          up vote
                          3
                          down vote









                          A batch can process up to 50 million records. Based on documentation
                          , I think you may want to change your code in the following ways:



                          1. Create a global string variable, call it "queryString" for example - which holds the query for both recordtypes (I.E 'Where RecordTypeId IN: recordTypeIds')


                          2. Change the start() method to return type DataBase.queryLocator, and within the start method call Database.queryLocator(queryString).






                          share|improve this answer












                          A batch can process up to 50 million records. Based on documentation
                          , I think you may want to change your code in the following ways:



                          1. Create a global string variable, call it "queryString" for example - which holds the query for both recordtypes (I.E 'Where RecordTypeId IN: recordTypeIds')


                          2. Change the start() method to return type DataBase.queryLocator, and within the start method call Database.queryLocator(queryString).







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Aug 22 at 21:38









                          kabdelr00

                          404




                          404



























                               

                              draft saved


                              draft discarded















































                               


                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f229818%2fhow-to-process-more-than-25-batches-of-2000-records%23new-answer', 'question_page');

                              );

                              Post as a guest













































































                              Comments

                              Popular posts from this blog

                              What does second last employer means? [closed]

                              Installing NextGIS Connect into QGIS 3?

                              One-line joke