APEX Scheduled jobs stuck in queue status
Clash 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
apex scheduled-apex
add a comment |Â
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
apex scheduled-apex
add a comment |Â
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
apex scheduled-apex
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
apex scheduled-apex
apex scheduled-apex
edited 4 hours ago
asked 4 hours ago
Arief Gunawan Tjiptorahardja
839
839
add a comment |Â
add a comment |Â
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
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
add a comment |Â
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
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
add a comment |Â
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
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
add a comment |Â
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
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
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
add a comment |Â
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
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password