始めはスケジュールされたフローを使う予定でしたが、エラーを解消できなかったです。
/*
* 053の申請を取得する Flowから呼び出す
*/
@InvocableMethod(label='get_Jobcan053B2')
public static void get_Jobcan053B2() {
//BAT_jobcan_calloutがなくても、実行できるように改造 2024-12-27
//更に改造 2025-01-15
List<Jobcan053__c> insertList53 = jobcan_callout2.calljobcan_org2List();
List<Jobcan053__c> upsertJList53 = jobcan_callout2.calljobcan_org2b(insertList53);//upsert insertList53 JobcanId__c;
List<Jobcan053__c> upsertJList53B = jobcan_callout6.Jobcan053toTaskBatchB(upsertJList53);
//if (upsertJList53B.size() >0 ) upsert upsertJList53B JobcanId__c;
system.debug('upsertJList53B==>' + upsertJList53B);
List<Jobcan053__c> upsertJList53C = jobcan_callout5.calljobcan_org2B(upsertJList53B);
system.debug('upsertJList53C==>' + upsertJList53C);
if (upsertJList53C.size() >0 ) upsert upsertJList53C JobcanId__c;
}
やっぱりスケジュールできるApexにします。
public void execute(SchedulableContext SC) {
//BAT_jobcan_calloutがなくても、実行できるように改造 2024-12-27
//更に改造 2025-01-15
List<Jobcan053__c> insertList53 = jobcan_callout2.calljobcan_org2List();
List<Jobcan053__c> upsertJList53 = jobcan_callout2.calljobcan_org2b(insertList53);//upsert insertList53 JobcanId__c;
List<Jobcan053__c> upsertJList53B = jobcan_callout6.Jobcan053toTaskBatchB(upsertJList53);
//if (upsertJList53B.size() >0 ) upsert upsertJList53B JobcanId__c;
system.debug('upsertJList53B==>' + upsertJList53B);
List<Jobcan053__c> upsertJList53C = jobcan_callout5.calljobcan_org2B(upsertJList53B);
system.debug('upsertJList53C==>' + upsertJList53C);
if (upsertJList53C.size() >0 ) upsert upsertJList53C JobcanId__c;
}
匿名ウィンドウで実行
ScheduledJobcan053 s = new ScheduledJobcan053();
String sch = '0 30 9 * * ?';
String jobID = System.schedule('Jobcan 053', sch, s);
起動できたかを確かめます
SELECT TimesTriggered, NextFireTime,CronExpression,State,CronJobDetail.Name,CronJobDetail.jobType FROM CronTrigger
ちゃんと起動してますね。
ああああ、エラーです。ええええ、サポートしてない?何で?
System.CalloutException: Callout from scheduled Apex not supported.
スケジュールされたジョブからコールアウトを行うことはできません。これを修正するには、スケジュールされたジョブから future または queueable を呼び出します。
global class SchedulableExchangeRate implements Schedulable {
global void execute(SchedulableContext ctx){
CurrencyExchangeController.calloutCurrency();
}
}
public class CurrencyExchangeController {
@future(callout=true) public static void calloutCurrency(){
//here is the code of my method
}
}
書き換えようと思ったけど、保存できません
このスケジュール可能なクラスに待機中または処理中のジョブがあります。CronTrigger ID (08eBC000008UZ8q)
以下でジョブを止めたら保存できました
System.abortJob('08eBC000008UZ8q');
何故かエラーになってスケジュールができません
Dependent class is invalid and needs recompilation: Class ScheduledJobcan053 : Static method cannot be referenced from a non static context: void CurrencyExchangeController.calloutCurrency()
以下に書き換えたらOKになった。
public void execute(SchedulableContext SC) {
//CurrencyExchangeController newCurExcContr = new CurrencyExchangeController();
//newCurExcContr.calloutCurrency();
CurrencyExchangeController.calloutCurrency();
}
無事に指定した時間で起動できました...