Apex more than 50 Queueble jobsSend chatter files with RESTList has more than 1 row for assignment to SObjectAPEX CPU Time limit exceeded error. Any suggestions?Trying to implement a batchable wrapperfault string: No such parameter param defined for the operation, please check the WSDL for the serviceSignificant elapsed time differences when calling sort() on different Comparable implementationsAre queueable jobs actually queueable?turn an APEX trigger into scheduled batch update

Why do banks “park” their money at the European Central Bank?

"There were either twelve sexes or none."

Duplicate instruments in unison in an orchestra

Did anyone try to find the little box that held Professor Moriarty and his wife after the crash?

Disambiguation of "nobis vobis" and "nobis nobis"

Nothing like a good ol' game of ModTen

Sum ergo cogito?

Is MOSFET active device?

If two Lore Bards used cutting words on an ability check or attack, would they stack?

Asymmetric table

What are some interesting features that are common cross-linguistically but don't exist in English?

Can I get temporary health insurance while moving to the US?

How many String objects would be created when concatenating multiple Strings?

"Sorry to bother you" in an email?

Where was Carl Sagan working on a plan to detonate a nuke on the Moon? Where was he applying when he leaked it?

Can a Rogue PC teach an NPC to perform Sneak Attack?

Was there ever a treaty between 2 entities with significantly different translations to the detriment of one party?

“T” in subscript in formulas

Does an atom recoil when photon radiate?

What is the difference between Major and Minor Bug?

Obtaining the intermediate solutions in AMPL

How do I prevent other wifi networks from showing up on my computer?

Prevent use of CNAME Record for Untrusted Domain

Would the Republic of Ireland and Northern Ireland be interested in reuniting?



Apex more than 50 Queueble jobs


Send chatter files with RESTList has more than 1 row for assignment to SObjectAPEX CPU Time limit exceeded error. Any suggestions?Trying to implement a batchable wrapperfault string: No such parameter param defined for the operation, please check the WSDL for the serviceSignificant elapsed time differences when calling sort() on different Comparable implementationsAre queueable jobs actually queueable?turn an APEX trigger into scheduled batch update






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








3















I have this class that call a Queueble job more than 50 times in a loop.
I recive the error: Too many queueable jobs added to the queue. The limit is 50.



Here is the class:



global class NSStatusOrderCronSC implements Schedulable 
global void execute(SchedulableContext sc)

String norder;
String IdOpp;
List<Opportunity> opList = [SELECT Id FROM Opportunity Where StageName != 'Cerrado Ganado' AND StageName != 'Cancelado'];
List<Order> acList = [SELECT Pedido__c, Oportunidad__c FROM Order WHERE Pedido__c != null AND Oportunidad__c in :opList];
for(Order ac : acList)

IdOpp = ac.Oportunidad__c;
norder = ac.Pedido__c;
if(!acList.isEmpty())
ID jobID = System.enqueueJob(new NSQueuebleJob(IdOpp, norder));






Inside the NSQueuebleJob i have this:



public class NSQueuebleJob implements Queueable, Database.AllowsCallouts 

private String IdOpp;
private String norder;

public NSQueuebleJob(String IdOpp, String norder)
this.IdOpp = IdOpp;
this.norder = norder;


public void execute(QueueableContext context)
String endpoint = 'http://url;
HttpRequest req = new HttpRequest();
req.setEndpoint(endpoint);
req.setMethod('GET');
req.setHeader('Content-Type', 'application/json');

//LOGIC to update some fields




How can i search all the opportunities that have created orders and update some fields without reaching the limit?










share|improve this question






























    3















    I have this class that call a Queueble job more than 50 times in a loop.
    I recive the error: Too many queueable jobs added to the queue. The limit is 50.



    Here is the class:



    global class NSStatusOrderCronSC implements Schedulable 
    global void execute(SchedulableContext sc)

    String norder;
    String IdOpp;
    List<Opportunity> opList = [SELECT Id FROM Opportunity Where StageName != 'Cerrado Ganado' AND StageName != 'Cancelado'];
    List<Order> acList = [SELECT Pedido__c, Oportunidad__c FROM Order WHERE Pedido__c != null AND Oportunidad__c in :opList];
    for(Order ac : acList)

    IdOpp = ac.Oportunidad__c;
    norder = ac.Pedido__c;
    if(!acList.isEmpty())
    ID jobID = System.enqueueJob(new NSQueuebleJob(IdOpp, norder));






    Inside the NSQueuebleJob i have this:



    public class NSQueuebleJob implements Queueable, Database.AllowsCallouts 

    private String IdOpp;
    private String norder;

    public NSQueuebleJob(String IdOpp, String norder)
    this.IdOpp = IdOpp;
    this.norder = norder;


    public void execute(QueueableContext context)
    String endpoint = 'http://url;
    HttpRequest req = new HttpRequest();
    req.setEndpoint(endpoint);
    req.setMethod('GET');
    req.setHeader('Content-Type', 'application/json');

    //LOGIC to update some fields




    How can i search all the opportunities that have created orders and update some fields without reaching the limit?










    share|improve this question


























      3












      3








      3








      I have this class that call a Queueble job more than 50 times in a loop.
      I recive the error: Too many queueable jobs added to the queue. The limit is 50.



      Here is the class:



      global class NSStatusOrderCronSC implements Schedulable 
      global void execute(SchedulableContext sc)

      String norder;
      String IdOpp;
      List<Opportunity> opList = [SELECT Id FROM Opportunity Where StageName != 'Cerrado Ganado' AND StageName != 'Cancelado'];
      List<Order> acList = [SELECT Pedido__c, Oportunidad__c FROM Order WHERE Pedido__c != null AND Oportunidad__c in :opList];
      for(Order ac : acList)

      IdOpp = ac.Oportunidad__c;
      norder = ac.Pedido__c;
      if(!acList.isEmpty())
      ID jobID = System.enqueueJob(new NSQueuebleJob(IdOpp, norder));






      Inside the NSQueuebleJob i have this:



      public class NSQueuebleJob implements Queueable, Database.AllowsCallouts 

      private String IdOpp;
      private String norder;

      public NSQueuebleJob(String IdOpp, String norder)
      this.IdOpp = IdOpp;
      this.norder = norder;


      public void execute(QueueableContext context)
      String endpoint = 'http://url;
      HttpRequest req = new HttpRequest();
      req.setEndpoint(endpoint);
      req.setMethod('GET');
      req.setHeader('Content-Type', 'application/json');

      //LOGIC to update some fields




      How can i search all the opportunities that have created orders and update some fields without reaching the limit?










      share|improve this question














      I have this class that call a Queueble job more than 50 times in a loop.
      I recive the error: Too many queueable jobs added to the queue. The limit is 50.



      Here is the class:



      global class NSStatusOrderCronSC implements Schedulable 
      global void execute(SchedulableContext sc)

      String norder;
      String IdOpp;
      List<Opportunity> opList = [SELECT Id FROM Opportunity Where StageName != 'Cerrado Ganado' AND StageName != 'Cancelado'];
      List<Order> acList = [SELECT Pedido__c, Oportunidad__c FROM Order WHERE Pedido__c != null AND Oportunidad__c in :opList];
      for(Order ac : acList)

      IdOpp = ac.Oportunidad__c;
      norder = ac.Pedido__c;
      if(!acList.isEmpty())
      ID jobID = System.enqueueJob(new NSQueuebleJob(IdOpp, norder));






      Inside the NSQueuebleJob i have this:



      public class NSQueuebleJob implements Queueable, Database.AllowsCallouts 

      private String IdOpp;
      private String norder;

      public NSQueuebleJob(String IdOpp, String norder)
      this.IdOpp = IdOpp;
      this.norder = norder;


      public void execute(QueueableContext context)
      String endpoint = 'http://url;
      HttpRequest req = new HttpRequest();
      req.setEndpoint(endpoint);
      req.setMethod('GET');
      req.setHeader('Content-Type', 'application/json');

      //LOGIC to update some fields




      How can i search all the opportunities that have created orders and update some fields without reaching the limit?







      apex class queueable-apex






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Aug 12 at 14:19









      OscarOscar

      124 bronze badges




      124 bronze badges























          3 Answers
          3






          active

          oldest

          votes


















          3















          Why don't you use Queueable to process a 'Queue' of Order's?



          As per the docs:




          No limit is enforced on the depth of chained jobs, which means that
          you can chain one job to another job and repeat this process with each
          new child job to link it to a new child job. For Developer Edition and
          Trial organizations, the maximum stack depth for chained jobs is 5,
          which means that you can chain jobs four times and the maximum number
          of jobs in the chain is 5, including the initial parent queueable job.




          This means you can use a list of SObjects as the 'queue' and then process them one by one until you get to the bottom of your chain. I've included an example of how you might do this.



          global class NSStatusOrderCronSC implements Schedulable 
          global void execute(SchedulableContext sc)

          String norder;
          String IdOpp;
          List<Opportunity> opList = [SELECT Id FROM Opportunity Where StageName != 'Cerrado Ganado' AND StageName != 'Cancelado'];
          List<Order> acList = [SELECT Pedido__c, Oportunidad__c FROM Order WHERE Pedido__c != null AND Oportunidad__c in :opList];

          if(!acList.isEmpty())
          ID jobID = System.enqueueJob(new NSQueuebleJob(acList));



          public class NSQueuebleJob implements Queueable, Database.AllowsCallouts
          private List<Order> orders;
          public NSQueuebleJob(List<Order> orders)

          this.orders = orders;


          public void execute(QueueableContext qc)

          Order order = orders.remove(0);

          // do whatever you intended to do

          // still more to process?
          if(orders.size() > 0)

          ID jobID = System.enqueueJob(new NSQueuebleJob(orders));









          share|improve this answer
































            2















            One of the approach could be to make a Queueable job to make few requests per execution to external endpoint and then process all the returned data. For example:



            public class NSQueuebleJob implements Queueable, Database.AllowsCallouts 

            private Map<id, String> OpportunitiesToProcess;

            public NSQueuebleJob(Map<Id, String> inputOpportunities)
            OpportunitiesToProcess = inputOpportunities;


            public void execute(QueueableContext context)
            Map<Id, String> response_map = new Map<Id, String>();
            Http http = new Http();

            for(Id opportunity_id : OpportunitiesToProcess)
            String endpoint = constructURL(opportunity_id, OpportunitiesToProcess.get(opportunity_id));
            HttpRequest req = new HttpRequest();
            req.setEndpoint(endpoint);
            HttpResponse response = http.send(request_instance);
            responseMap.put(opportunity_id, response.getBody());


            for(Id opportunity_id : response_map)
            //Logic to update some fields + collect all changes

            //Logic to perform a DML regarding previously updated fields




            In the given example, you can pass few records into your queueable job:



            List<Opportunity> opList = [SELECT Id FROM Opportunity Where StageName != 'Cerrado Ganado' AND StageName != 'Cancelado'];
            List<Order> acList = [SELECT Pedido__c, Oportunidad__c FROM Order WHERE Pedido__c != null AND Oportunidad__c in :opList];
            Map<Id, String> queueable_job_params = new Map<Id, String>();
            for(Order ac : acList)

            IdOpp = ac.Oportunidad__c;
            norder = ac.Pedido__c;
            if(!acList.isEmpty())
            queueable_job_params.put(ac.Oportunidad__c, ac.Pedido__c);
            ID jobID =

            if (queueable_job_params.size() >= 20)
            System.enqueueJob(new NSQueuebleJob(queueable_job_params));
            queueable_job_params.clear();


            if (!queueable_job_params.isEmpty())
            System.enqueueJob(new NSQueuebleJob(queueable_job_params));



            In this case, you might decide which number of records should be passed into the single instance of queueable job execution. In case if there are a lot of records included -- it would be more wise to use an apex batch job.



            Another approach could be Chaining -- basically pass all of the records into Queueable job, but process only as many, as you can based on your Heap Size/ Callout amount/ Total Callout Duration limit(s) per single execution.






            share|improve this answer
































              0















              In addition to the answers herein; I always preface any attempt to enqueue a Queueable with this



              if (Util.isEnqueueable) {
              System.enqueueJob(...);
              else
              some fallback strategy - like using a schedulable



              where Util.isEnqueueable looks like this:



              public static Boolean isEnqueueable 
              get
              return isEnqueueable == null
              ? Limits.getLimitQueueableJobs() - Limits.getQueueableJobs() > 0
              : isEnqueueable;
              set;



              A static variable (rather than method) is used so testMethods can coerce the state to false and allow for testing of the fallback logic.






              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',
                autoActivateHeartbeat: false,
                convertImagesToLinks: false,
                noModals: true,
                showLowRepImageUploadWarning: true,
                reputationToPostImages: null,
                bindNavPrevention: true,
                postfix: "",
                imageUploader:
                brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                allowUrls: true
                ,
                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%2f273276%2fapex-more-than-50-queueble-jobs%23new-answer', 'question_page');

                );

                Post as a guest















                Required, but never shown

























                3 Answers
                3






                active

                oldest

                votes








                3 Answers
                3






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes









                3















                Why don't you use Queueable to process a 'Queue' of Order's?



                As per the docs:




                No limit is enforced on the depth of chained jobs, which means that
                you can chain one job to another job and repeat this process with each
                new child job to link it to a new child job. For Developer Edition and
                Trial organizations, the maximum stack depth for chained jobs is 5,
                which means that you can chain jobs four times and the maximum number
                of jobs in the chain is 5, including the initial parent queueable job.




                This means you can use a list of SObjects as the 'queue' and then process them one by one until you get to the bottom of your chain. I've included an example of how you might do this.



                global class NSStatusOrderCronSC implements Schedulable 
                global void execute(SchedulableContext sc)

                String norder;
                String IdOpp;
                List<Opportunity> opList = [SELECT Id FROM Opportunity Where StageName != 'Cerrado Ganado' AND StageName != 'Cancelado'];
                List<Order> acList = [SELECT Pedido__c, Oportunidad__c FROM Order WHERE Pedido__c != null AND Oportunidad__c in :opList];

                if(!acList.isEmpty())
                ID jobID = System.enqueueJob(new NSQueuebleJob(acList));



                public class NSQueuebleJob implements Queueable, Database.AllowsCallouts
                private List<Order> orders;
                public NSQueuebleJob(List<Order> orders)

                this.orders = orders;


                public void execute(QueueableContext qc)

                Order order = orders.remove(0);

                // do whatever you intended to do

                // still more to process?
                if(orders.size() > 0)

                ID jobID = System.enqueueJob(new NSQueuebleJob(orders));









                share|improve this answer





























                  3















                  Why don't you use Queueable to process a 'Queue' of Order's?



                  As per the docs:




                  No limit is enforced on the depth of chained jobs, which means that
                  you can chain one job to another job and repeat this process with each
                  new child job to link it to a new child job. For Developer Edition and
                  Trial organizations, the maximum stack depth for chained jobs is 5,
                  which means that you can chain jobs four times and the maximum number
                  of jobs in the chain is 5, including the initial parent queueable job.




                  This means you can use a list of SObjects as the 'queue' and then process them one by one until you get to the bottom of your chain. I've included an example of how you might do this.



                  global class NSStatusOrderCronSC implements Schedulable 
                  global void execute(SchedulableContext sc)

                  String norder;
                  String IdOpp;
                  List<Opportunity> opList = [SELECT Id FROM Opportunity Where StageName != 'Cerrado Ganado' AND StageName != 'Cancelado'];
                  List<Order> acList = [SELECT Pedido__c, Oportunidad__c FROM Order WHERE Pedido__c != null AND Oportunidad__c in :opList];

                  if(!acList.isEmpty())
                  ID jobID = System.enqueueJob(new NSQueuebleJob(acList));



                  public class NSQueuebleJob implements Queueable, Database.AllowsCallouts
                  private List<Order> orders;
                  public NSQueuebleJob(List<Order> orders)

                  this.orders = orders;


                  public void execute(QueueableContext qc)

                  Order order = orders.remove(0);

                  // do whatever you intended to do

                  // still more to process?
                  if(orders.size() > 0)

                  ID jobID = System.enqueueJob(new NSQueuebleJob(orders));









                  share|improve this answer



























                    3














                    3










                    3









                    Why don't you use Queueable to process a 'Queue' of Order's?



                    As per the docs:




                    No limit is enforced on the depth of chained jobs, which means that
                    you can chain one job to another job and repeat this process with each
                    new child job to link it to a new child job. For Developer Edition and
                    Trial organizations, the maximum stack depth for chained jobs is 5,
                    which means that you can chain jobs four times and the maximum number
                    of jobs in the chain is 5, including the initial parent queueable job.




                    This means you can use a list of SObjects as the 'queue' and then process them one by one until you get to the bottom of your chain. I've included an example of how you might do this.



                    global class NSStatusOrderCronSC implements Schedulable 
                    global void execute(SchedulableContext sc)

                    String norder;
                    String IdOpp;
                    List<Opportunity> opList = [SELECT Id FROM Opportunity Where StageName != 'Cerrado Ganado' AND StageName != 'Cancelado'];
                    List<Order> acList = [SELECT Pedido__c, Oportunidad__c FROM Order WHERE Pedido__c != null AND Oportunidad__c in :opList];

                    if(!acList.isEmpty())
                    ID jobID = System.enqueueJob(new NSQueuebleJob(acList));



                    public class NSQueuebleJob implements Queueable, Database.AllowsCallouts
                    private List<Order> orders;
                    public NSQueuebleJob(List<Order> orders)

                    this.orders = orders;


                    public void execute(QueueableContext qc)

                    Order order = orders.remove(0);

                    // do whatever you intended to do

                    // still more to process?
                    if(orders.size() > 0)

                    ID jobID = System.enqueueJob(new NSQueuebleJob(orders));









                    share|improve this answer













                    Why don't you use Queueable to process a 'Queue' of Order's?



                    As per the docs:




                    No limit is enforced on the depth of chained jobs, which means that
                    you can chain one job to another job and repeat this process with each
                    new child job to link it to a new child job. For Developer Edition and
                    Trial organizations, the maximum stack depth for chained jobs is 5,
                    which means that you can chain jobs four times and the maximum number
                    of jobs in the chain is 5, including the initial parent queueable job.




                    This means you can use a list of SObjects as the 'queue' and then process them one by one until you get to the bottom of your chain. I've included an example of how you might do this.



                    global class NSStatusOrderCronSC implements Schedulable 
                    global void execute(SchedulableContext sc)

                    String norder;
                    String IdOpp;
                    List<Opportunity> opList = [SELECT Id FROM Opportunity Where StageName != 'Cerrado Ganado' AND StageName != 'Cancelado'];
                    List<Order> acList = [SELECT Pedido__c, Oportunidad__c FROM Order WHERE Pedido__c != null AND Oportunidad__c in :opList];

                    if(!acList.isEmpty())
                    ID jobID = System.enqueueJob(new NSQueuebleJob(acList));



                    public class NSQueuebleJob implements Queueable, Database.AllowsCallouts
                    private List<Order> orders;
                    public NSQueuebleJob(List<Order> orders)

                    this.orders = orders;


                    public void execute(QueueableContext qc)

                    Order order = orders.remove(0);

                    // do whatever you intended to do

                    // still more to process?
                    if(orders.size() > 0)

                    ID jobID = System.enqueueJob(new NSQueuebleJob(orders));










                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Aug 12 at 15:06









                    Phil HawthornPhil Hawthorn

                    13.7k3 gold badges35 silver badges65 bronze badges




                    13.7k3 gold badges35 silver badges65 bronze badges


























                        2















                        One of the approach could be to make a Queueable job to make few requests per execution to external endpoint and then process all the returned data. For example:



                        public class NSQueuebleJob implements Queueable, Database.AllowsCallouts 

                        private Map<id, String> OpportunitiesToProcess;

                        public NSQueuebleJob(Map<Id, String> inputOpportunities)
                        OpportunitiesToProcess = inputOpportunities;


                        public void execute(QueueableContext context)
                        Map<Id, String> response_map = new Map<Id, String>();
                        Http http = new Http();

                        for(Id opportunity_id : OpportunitiesToProcess)
                        String endpoint = constructURL(opportunity_id, OpportunitiesToProcess.get(opportunity_id));
                        HttpRequest req = new HttpRequest();
                        req.setEndpoint(endpoint);
                        HttpResponse response = http.send(request_instance);
                        responseMap.put(opportunity_id, response.getBody());


                        for(Id opportunity_id : response_map)
                        //Logic to update some fields + collect all changes

                        //Logic to perform a DML regarding previously updated fields




                        In the given example, you can pass few records into your queueable job:



                        List<Opportunity> opList = [SELECT Id FROM Opportunity Where StageName != 'Cerrado Ganado' AND StageName != 'Cancelado'];
                        List<Order> acList = [SELECT Pedido__c, Oportunidad__c FROM Order WHERE Pedido__c != null AND Oportunidad__c in :opList];
                        Map<Id, String> queueable_job_params = new Map<Id, String>();
                        for(Order ac : acList)

                        IdOpp = ac.Oportunidad__c;
                        norder = ac.Pedido__c;
                        if(!acList.isEmpty())
                        queueable_job_params.put(ac.Oportunidad__c, ac.Pedido__c);
                        ID jobID =

                        if (queueable_job_params.size() >= 20)
                        System.enqueueJob(new NSQueuebleJob(queueable_job_params));
                        queueable_job_params.clear();


                        if (!queueable_job_params.isEmpty())
                        System.enqueueJob(new NSQueuebleJob(queueable_job_params));



                        In this case, you might decide which number of records should be passed into the single instance of queueable job execution. In case if there are a lot of records included -- it would be more wise to use an apex batch job.



                        Another approach could be Chaining -- basically pass all of the records into Queueable job, but process only as many, as you can based on your Heap Size/ Callout amount/ Total Callout Duration limit(s) per single execution.






                        share|improve this answer





























                          2















                          One of the approach could be to make a Queueable job to make few requests per execution to external endpoint and then process all the returned data. For example:



                          public class NSQueuebleJob implements Queueable, Database.AllowsCallouts 

                          private Map<id, String> OpportunitiesToProcess;

                          public NSQueuebleJob(Map<Id, String> inputOpportunities)
                          OpportunitiesToProcess = inputOpportunities;


                          public void execute(QueueableContext context)
                          Map<Id, String> response_map = new Map<Id, String>();
                          Http http = new Http();

                          for(Id opportunity_id : OpportunitiesToProcess)
                          String endpoint = constructURL(opportunity_id, OpportunitiesToProcess.get(opportunity_id));
                          HttpRequest req = new HttpRequest();
                          req.setEndpoint(endpoint);
                          HttpResponse response = http.send(request_instance);
                          responseMap.put(opportunity_id, response.getBody());


                          for(Id opportunity_id : response_map)
                          //Logic to update some fields + collect all changes

                          //Logic to perform a DML regarding previously updated fields




                          In the given example, you can pass few records into your queueable job:



                          List<Opportunity> opList = [SELECT Id FROM Opportunity Where StageName != 'Cerrado Ganado' AND StageName != 'Cancelado'];
                          List<Order> acList = [SELECT Pedido__c, Oportunidad__c FROM Order WHERE Pedido__c != null AND Oportunidad__c in :opList];
                          Map<Id, String> queueable_job_params = new Map<Id, String>();
                          for(Order ac : acList)

                          IdOpp = ac.Oportunidad__c;
                          norder = ac.Pedido__c;
                          if(!acList.isEmpty())
                          queueable_job_params.put(ac.Oportunidad__c, ac.Pedido__c);
                          ID jobID =

                          if (queueable_job_params.size() >= 20)
                          System.enqueueJob(new NSQueuebleJob(queueable_job_params));
                          queueable_job_params.clear();


                          if (!queueable_job_params.isEmpty())
                          System.enqueueJob(new NSQueuebleJob(queueable_job_params));



                          In this case, you might decide which number of records should be passed into the single instance of queueable job execution. In case if there are a lot of records included -- it would be more wise to use an apex batch job.



                          Another approach could be Chaining -- basically pass all of the records into Queueable job, but process only as many, as you can based on your Heap Size/ Callout amount/ Total Callout Duration limit(s) per single execution.






                          share|improve this answer



























                            2














                            2










                            2









                            One of the approach could be to make a Queueable job to make few requests per execution to external endpoint and then process all the returned data. For example:



                            public class NSQueuebleJob implements Queueable, Database.AllowsCallouts 

                            private Map<id, String> OpportunitiesToProcess;

                            public NSQueuebleJob(Map<Id, String> inputOpportunities)
                            OpportunitiesToProcess = inputOpportunities;


                            public void execute(QueueableContext context)
                            Map<Id, String> response_map = new Map<Id, String>();
                            Http http = new Http();

                            for(Id opportunity_id : OpportunitiesToProcess)
                            String endpoint = constructURL(opportunity_id, OpportunitiesToProcess.get(opportunity_id));
                            HttpRequest req = new HttpRequest();
                            req.setEndpoint(endpoint);
                            HttpResponse response = http.send(request_instance);
                            responseMap.put(opportunity_id, response.getBody());


                            for(Id opportunity_id : response_map)
                            //Logic to update some fields + collect all changes

                            //Logic to perform a DML regarding previously updated fields




                            In the given example, you can pass few records into your queueable job:



                            List<Opportunity> opList = [SELECT Id FROM Opportunity Where StageName != 'Cerrado Ganado' AND StageName != 'Cancelado'];
                            List<Order> acList = [SELECT Pedido__c, Oportunidad__c FROM Order WHERE Pedido__c != null AND Oportunidad__c in :opList];
                            Map<Id, String> queueable_job_params = new Map<Id, String>();
                            for(Order ac : acList)

                            IdOpp = ac.Oportunidad__c;
                            norder = ac.Pedido__c;
                            if(!acList.isEmpty())
                            queueable_job_params.put(ac.Oportunidad__c, ac.Pedido__c);
                            ID jobID =

                            if (queueable_job_params.size() >= 20)
                            System.enqueueJob(new NSQueuebleJob(queueable_job_params));
                            queueable_job_params.clear();


                            if (!queueable_job_params.isEmpty())
                            System.enqueueJob(new NSQueuebleJob(queueable_job_params));



                            In this case, you might decide which number of records should be passed into the single instance of queueable job execution. In case if there are a lot of records included -- it would be more wise to use an apex batch job.



                            Another approach could be Chaining -- basically pass all of the records into Queueable job, but process only as many, as you can based on your Heap Size/ Callout amount/ Total Callout Duration limit(s) per single execution.






                            share|improve this answer













                            One of the approach could be to make a Queueable job to make few requests per execution to external endpoint and then process all the returned data. For example:



                            public class NSQueuebleJob implements Queueable, Database.AllowsCallouts 

                            private Map<id, String> OpportunitiesToProcess;

                            public NSQueuebleJob(Map<Id, String> inputOpportunities)
                            OpportunitiesToProcess = inputOpportunities;


                            public void execute(QueueableContext context)
                            Map<Id, String> response_map = new Map<Id, String>();
                            Http http = new Http();

                            for(Id opportunity_id : OpportunitiesToProcess)
                            String endpoint = constructURL(opportunity_id, OpportunitiesToProcess.get(opportunity_id));
                            HttpRequest req = new HttpRequest();
                            req.setEndpoint(endpoint);
                            HttpResponse response = http.send(request_instance);
                            responseMap.put(opportunity_id, response.getBody());


                            for(Id opportunity_id : response_map)
                            //Logic to update some fields + collect all changes

                            //Logic to perform a DML regarding previously updated fields




                            In the given example, you can pass few records into your queueable job:



                            List<Opportunity> opList = [SELECT Id FROM Opportunity Where StageName != 'Cerrado Ganado' AND StageName != 'Cancelado'];
                            List<Order> acList = [SELECT Pedido__c, Oportunidad__c FROM Order WHERE Pedido__c != null AND Oportunidad__c in :opList];
                            Map<Id, String> queueable_job_params = new Map<Id, String>();
                            for(Order ac : acList)

                            IdOpp = ac.Oportunidad__c;
                            norder = ac.Pedido__c;
                            if(!acList.isEmpty())
                            queueable_job_params.put(ac.Oportunidad__c, ac.Pedido__c);
                            ID jobID =

                            if (queueable_job_params.size() >= 20)
                            System.enqueueJob(new NSQueuebleJob(queueable_job_params));
                            queueable_job_params.clear();


                            if (!queueable_job_params.isEmpty())
                            System.enqueueJob(new NSQueuebleJob(queueable_job_params));



                            In this case, you might decide which number of records should be passed into the single instance of queueable job execution. In case if there are a lot of records included -- it would be more wise to use an apex batch job.



                            Another approach could be Chaining -- basically pass all of the records into Queueable job, but process only as many, as you can based on your Heap Size/ Callout amount/ Total Callout Duration limit(s) per single execution.







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Aug 12 at 14:40









                            kurunvekurunve

                            2,8592 gold badges13 silver badges24 bronze badges




                            2,8592 gold badges13 silver badges24 bronze badges
























                                0















                                In addition to the answers herein; I always preface any attempt to enqueue a Queueable with this



                                if (Util.isEnqueueable) {
                                System.enqueueJob(...);
                                else
                                some fallback strategy - like using a schedulable



                                where Util.isEnqueueable looks like this:



                                public static Boolean isEnqueueable 
                                get
                                return isEnqueueable == null
                                ? Limits.getLimitQueueableJobs() - Limits.getQueueableJobs() > 0
                                : isEnqueueable;
                                set;



                                A static variable (rather than method) is used so testMethods can coerce the state to false and allow for testing of the fallback logic.






                                share|improve this answer





























                                  0















                                  In addition to the answers herein; I always preface any attempt to enqueue a Queueable with this



                                  if (Util.isEnqueueable) {
                                  System.enqueueJob(...);
                                  else
                                  some fallback strategy - like using a schedulable



                                  where Util.isEnqueueable looks like this:



                                  public static Boolean isEnqueueable 
                                  get
                                  return isEnqueueable == null
                                  ? Limits.getLimitQueueableJobs() - Limits.getQueueableJobs() > 0
                                  : isEnqueueable;
                                  set;



                                  A static variable (rather than method) is used so testMethods can coerce the state to false and allow for testing of the fallback logic.






                                  share|improve this answer



























                                    0














                                    0










                                    0









                                    In addition to the answers herein; I always preface any attempt to enqueue a Queueable with this



                                    if (Util.isEnqueueable) {
                                    System.enqueueJob(...);
                                    else
                                    some fallback strategy - like using a schedulable



                                    where Util.isEnqueueable looks like this:



                                    public static Boolean isEnqueueable 
                                    get
                                    return isEnqueueable == null
                                    ? Limits.getLimitQueueableJobs() - Limits.getQueueableJobs() > 0
                                    : isEnqueueable;
                                    set;



                                    A static variable (rather than method) is used so testMethods can coerce the state to false and allow for testing of the fallback logic.






                                    share|improve this answer













                                    In addition to the answers herein; I always preface any attempt to enqueue a Queueable with this



                                    if (Util.isEnqueueable) {
                                    System.enqueueJob(...);
                                    else
                                    some fallback strategy - like using a schedulable



                                    where Util.isEnqueueable looks like this:



                                    public static Boolean isEnqueueable 
                                    get
                                    return isEnqueueable == null
                                    ? Limits.getLimitQueueableJobs() - Limits.getQueueableJobs() > 0
                                    : isEnqueueable;
                                    set;



                                    A static variable (rather than method) is used so testMethods can coerce the state to false and allow for testing of the fallback logic.







                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered Aug 13 at 1:25









                                    cropredycropredy

                                    39k4 gold badges47 silver badges137 bronze badges




                                    39k4 gold badges47 silver badges137 bronze badges






























                                        draft saved

                                        draft discarded
















































                                        Thanks for contributing an answer to Salesforce Stack Exchange!


                                        • Please be sure to answer the question. Provide details and share your research!

                                        But avoid


                                        • Asking for help, clarification, or responding to other answers.

                                        • Making statements based on opinion; back them up with references or personal experience.

                                        To learn more, see our tips on writing great answers.




                                        draft saved


                                        draft discarded














                                        StackExchange.ready(
                                        function ()
                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f273276%2fapex-more-than-50-queueble-jobs%23new-answer', 'question_page');

                                        );

                                        Post as a guest















                                        Required, but never shown





















































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown

































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown







                                        Popular posts from this blog

                                        Get product attribute by attribute group code in magento 2get product attribute by product attribute group in magento 2Magento 2 Log Bundle Product Data in List Page?How to get all product attribute of a attribute group of Default attribute set?Magento 2.1 Create a filter in the product grid by new attributeMagento 2 : Get Product Attribute values By GroupMagento 2 How to get all existing values for one attributeMagento 2 get custom attribute of a single product inside a pluginMagento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?Magento2: how to develop rest API to get new productsGet product attribute by attribute group code ( [attribute_group_code] ) in magento 2

                                        Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

                                        Magento 2.3: How do i solve this, Not registered handle, on custom form?How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 : File Upload issue in UI Component FormMagento2 Not registered handleHow to configured Form Builder Js in my custom magento 2.3.0 module?Magento 2.3. How to create image upload field in an admin form