APEX Scheduled jobs stuck in queue status

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 made scheduled class to get access token and save it to the custom object.. I set the scheduled jobs, using the UI (apex class > schedule apex), to run the class everyday.. but its not firing..



here`s my class



 global class Purecloud_Connector implements Schedulable
//public static String CRON_EXP = '0 0 1/1 * *';
global void execute(SchedulableContext ctx)
String clientId = '[CLIENT ID]';
String clientSecret = '[CLIENT SECRET]';
String connId = 'a1cO0000001UZ83IAG';
String accessToken;

HttpRequest req = new HttpRequest();
req.setMethod('POST');

req.setHeader('Authorization', 'Basic ' + EncodingUtil.base64Encode(Blob.valueOf(clientId + ':' + clientSecret)));
req.setHeader('Host','[HOST]');
req.setHeader('content-type', 'application/x-www-form-urlencoded');
req.setEndpoint('[END POINT]');

req.setBody('grant_type=client_credentials');

Http http = new Http();

try
HTTPResponse res = http.send(req);
System.debug('res:' + res);
System.debug('body:' + res.getBody());
JSONParser parser;
parser = JSON.createParser(res.getBody());
integer x = 0;
while (parser.nextToken() != null)
x++;
system.debug('countLoop:' + x);
if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) && (parser.getText() == 'access_token'))
parser.nextToken();
accessToken = parser.getText();


Purecloud_Connector__c conn = new Purecloud_Connector__c();
conn.id = connId;
conn.Access_Token__c = accessToken;
update conn;

catch(System.CalloutException e)
System.debug('exception:' + e);
// do something useful here





enter image description here










share|improve this question





























    up vote
    1
    down vote

    favorite












    I made scheduled class to get access token and save it to the custom object.. I set the scheduled jobs, using the UI (apex class > schedule apex), to run the class everyday.. but its not firing..



    here`s my class



     global class Purecloud_Connector implements Schedulable
    //public static String CRON_EXP = '0 0 1/1 * *';
    global void execute(SchedulableContext ctx)
    String clientId = '[CLIENT ID]';
    String clientSecret = '[CLIENT SECRET]';
    String connId = 'a1cO0000001UZ83IAG';
    String accessToken;

    HttpRequest req = new HttpRequest();
    req.setMethod('POST');

    req.setHeader('Authorization', 'Basic ' + EncodingUtil.base64Encode(Blob.valueOf(clientId + ':' + clientSecret)));
    req.setHeader('Host','[HOST]');
    req.setHeader('content-type', 'application/x-www-form-urlencoded');
    req.setEndpoint('[END POINT]');

    req.setBody('grant_type=client_credentials');

    Http http = new Http();

    try
    HTTPResponse res = http.send(req);
    System.debug('res:' + res);
    System.debug('body:' + res.getBody());
    JSONParser parser;
    parser = JSON.createParser(res.getBody());
    integer x = 0;
    while (parser.nextToken() != null)
    x++;
    system.debug('countLoop:' + x);
    if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) && (parser.getText() == 'access_token'))
    parser.nextToken();
    accessToken = parser.getText();


    Purecloud_Connector__c conn = new Purecloud_Connector__c();
    conn.id = connId;
    conn.Access_Token__c = accessToken;
    update conn;

    catch(System.CalloutException e)
    System.debug('exception:' + e);
    // do something useful here





    enter image description here










    share|improve this question

























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I made scheduled class to get access token and save it to the custom object.. I set the scheduled jobs, using the UI (apex class > schedule apex), to run the class everyday.. but its not firing..



      here`s my class



       global class Purecloud_Connector implements Schedulable
      //public static String CRON_EXP = '0 0 1/1 * *';
      global void execute(SchedulableContext ctx)
      String clientId = '[CLIENT ID]';
      String clientSecret = '[CLIENT SECRET]';
      String connId = 'a1cO0000001UZ83IAG';
      String accessToken;

      HttpRequest req = new HttpRequest();
      req.setMethod('POST');

      req.setHeader('Authorization', 'Basic ' + EncodingUtil.base64Encode(Blob.valueOf(clientId + ':' + clientSecret)));
      req.setHeader('Host','[HOST]');
      req.setHeader('content-type', 'application/x-www-form-urlencoded');
      req.setEndpoint('[END POINT]');

      req.setBody('grant_type=client_credentials');

      Http http = new Http();

      try
      HTTPResponse res = http.send(req);
      System.debug('res:' + res);
      System.debug('body:' + res.getBody());
      JSONParser parser;
      parser = JSON.createParser(res.getBody());
      integer x = 0;
      while (parser.nextToken() != null)
      x++;
      system.debug('countLoop:' + x);
      if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) && (parser.getText() == 'access_token'))
      parser.nextToken();
      accessToken = parser.getText();


      Purecloud_Connector__c conn = new Purecloud_Connector__c();
      conn.id = connId;
      conn.Access_Token__c = accessToken;
      update conn;

      catch(System.CalloutException e)
      System.debug('exception:' + e);
      // do something useful here





      enter image description here










      share|improve this question















      I made scheduled class to get access token and save it to the custom object.. I set the scheduled jobs, using the UI (apex class > schedule apex), to run the class everyday.. but its not firing..



      here`s my class



       global class Purecloud_Connector implements Schedulable
      //public static String CRON_EXP = '0 0 1/1 * *';
      global void execute(SchedulableContext ctx)
      String clientId = '[CLIENT ID]';
      String clientSecret = '[CLIENT SECRET]';
      String connId = 'a1cO0000001UZ83IAG';
      String accessToken;

      HttpRequest req = new HttpRequest();
      req.setMethod('POST');

      req.setHeader('Authorization', 'Basic ' + EncodingUtil.base64Encode(Blob.valueOf(clientId + ':' + clientSecret)));
      req.setHeader('Host','[HOST]');
      req.setHeader('content-type', 'application/x-www-form-urlencoded');
      req.setEndpoint('[END POINT]');

      req.setBody('grant_type=client_credentials');

      Http http = new Http();

      try
      HTTPResponse res = http.send(req);
      System.debug('res:' + res);
      System.debug('body:' + res.getBody());
      JSONParser parser;
      parser = JSON.createParser(res.getBody());
      integer x = 0;
      while (parser.nextToken() != null)
      x++;
      system.debug('countLoop:' + x);
      if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) && (parser.getText() == 'access_token'))
      parser.nextToken();
      accessToken = parser.getText();


      Purecloud_Connector__c conn = new Purecloud_Connector__c();
      conn.id = connId;
      conn.Access_Token__c = accessToken;
      update conn;

      catch(System.CalloutException e)
      System.debug('exception:' + e);
      // do something useful here





      enter image description here







      apex scheduled-apex






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 4 hours ago

























      asked 4 hours ago









      Arief Gunawan Tjiptorahardja

      839




      839




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          3
          down vote



          accepted










          We used to get System.CalloutException: Callout from scheduled Apex not supported Error when we are making an HTTP callout from a class which is implementing Database.Schedulable interface because Salesforce does not allow us to make callouts from Schedulable classes.If you want to do it in the scheduled class you will need to do it in an @future method.
          Readout :
          https://developer.salesforce.com/blogs/developer-relations/2010/02/spring-10-saw-the-general-availability-of-one-of-my-favorite-new-features-of-the-platform-the-apex-schedulerwith-the-apex-s.html






          share|improve this answer




















          • Oh I see, so technically I have to create 1 class for callout, and 1 class for the scheduler that call the callout class?
            – Arief Gunawan Tjiptorahardja
            3 hours ago










          • Yes, create a class which have future method with callout annotation. Please read out the suggested link.
            – Pragati Jain
            3 hours ago










          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%2f235854%2fapex-scheduled-jobs-stuck-in-queue-status%23new-answer', 'question_page');

          );

          Post as a guest






























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          3
          down vote



          accepted










          We used to get System.CalloutException: Callout from scheduled Apex not supported Error when we are making an HTTP callout from a class which is implementing Database.Schedulable interface because Salesforce does not allow us to make callouts from Schedulable classes.If you want to do it in the scheduled class you will need to do it in an @future method.
          Readout :
          https://developer.salesforce.com/blogs/developer-relations/2010/02/spring-10-saw-the-general-availability-of-one-of-my-favorite-new-features-of-the-platform-the-apex-schedulerwith-the-apex-s.html






          share|improve this answer




















          • Oh I see, so technically I have to create 1 class for callout, and 1 class for the scheduler that call the callout class?
            – Arief Gunawan Tjiptorahardja
            3 hours ago










          • Yes, create a class which have future method with callout annotation. Please read out the suggested link.
            – Pragati Jain
            3 hours ago














          up vote
          3
          down vote



          accepted










          We used to get System.CalloutException: Callout from scheduled Apex not supported Error when we are making an HTTP callout from a class which is implementing Database.Schedulable interface because Salesforce does not allow us to make callouts from Schedulable classes.If you want to do it in the scheduled class you will need to do it in an @future method.
          Readout :
          https://developer.salesforce.com/blogs/developer-relations/2010/02/spring-10-saw-the-general-availability-of-one-of-my-favorite-new-features-of-the-platform-the-apex-schedulerwith-the-apex-s.html






          share|improve this answer




















          • Oh I see, so technically I have to create 1 class for callout, and 1 class for the scheduler that call the callout class?
            – Arief Gunawan Tjiptorahardja
            3 hours ago










          • Yes, create a class which have future method with callout annotation. Please read out the suggested link.
            – Pragati Jain
            3 hours ago












          up vote
          3
          down vote



          accepted







          up vote
          3
          down vote



          accepted






          We used to get System.CalloutException: Callout from scheduled Apex not supported Error when we are making an HTTP callout from a class which is implementing Database.Schedulable interface because Salesforce does not allow us to make callouts from Schedulable classes.If you want to do it in the scheduled class you will need to do it in an @future method.
          Readout :
          https://developer.salesforce.com/blogs/developer-relations/2010/02/spring-10-saw-the-general-availability-of-one-of-my-favorite-new-features-of-the-platform-the-apex-schedulerwith-the-apex-s.html






          share|improve this answer












          We used to get System.CalloutException: Callout from scheduled Apex not supported Error when we are making an HTTP callout from a class which is implementing Database.Schedulable interface because Salesforce does not allow us to make callouts from Schedulable classes.If you want to do it in the scheduled class you will need to do it in an @future method.
          Readout :
          https://developer.salesforce.com/blogs/developer-relations/2010/02/spring-10-saw-the-general-availability-of-one-of-my-favorite-new-features-of-the-platform-the-apex-schedulerwith-the-apex-s.html







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 3 hours ago









          Pragati Jain

          54038




          54038











          • Oh I see, so technically I have to create 1 class for callout, and 1 class for the scheduler that call the callout class?
            – Arief Gunawan Tjiptorahardja
            3 hours ago










          • Yes, create a class which have future method with callout annotation. Please read out the suggested link.
            – Pragati Jain
            3 hours ago
















          • Oh I see, so technically I have to create 1 class for callout, and 1 class for the scheduler that call the callout class?
            – Arief Gunawan Tjiptorahardja
            3 hours ago










          • Yes, create a class which have future method with callout annotation. Please read out the suggested link.
            – Pragati Jain
            3 hours ago















          Oh I see, so technically I have to create 1 class for callout, and 1 class for the scheduler that call the callout class?
          – Arief Gunawan Tjiptorahardja
          3 hours ago




          Oh I see, so technically I have to create 1 class for callout, and 1 class for the scheduler that call the callout class?
          – Arief Gunawan Tjiptorahardja
          3 hours ago












          Yes, create a class which have future method with callout annotation. Please read out the suggested link.
          – Pragati Jain
          3 hours ago




          Yes, create a class which have future method with callout annotation. Please read out the suggested link.
          – Pragati Jain
          3 hours ago

















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f235854%2fapex-scheduled-jobs-stuck-in-queue-status%23new-answer', 'question_page');

          );

          Post as a guest













































































          Comments

          Popular posts from this blog

          What does second last employer means? [closed]

          List of Gilmore Girls characters

          One-line joke