UI でスケジュールされた Apex を使用するとき、スケジュールされたクラスを 1 回だけ実行するように設定できません。常に繰り返されます。これを回避するには、システムログ経由で System.scheduled を使用する必要があります。
注意: ここで示しているコードは、毎時の最後の 10 分間は機能しません。
String hour = String.valueOf(Datetime.now().hour());
String min = String.valueOf(Datetime.now().minute() + 10);
String ss = String.valueOf(Datetime.now().second());
//parse to cron expression
String nextFireTime = ss + ' ' + min + ' ' + hour + ' * * ?';
MyScheduledJob s = new MyScheduledJob();
System.schedule('Job Started At ' + String.valueOf(Datetime.now()), nextFireTime, s);
Schedulable インターフェースを実装する終了メソッドをクラスに追加して、ジョブを中止します。これにより、ジョブが 2 回以上実行されなくなります。
global void finish(Database.BatchableContext BC)
{
// Get the ID of the AsyncApexJob representing this batch job from Database.BatchableContext.
// Query the AsyncApexJob object to retrieve the current job's information.
AsyncApexJob a = [SELECT Id, Status, NumberOfErrors, JobItemsProcessed, TotalJobItems, CreatedBy.Email ..... FROM AsyncApexJob WHERE Id =
:BC.getJobId()];
//then use the active job id and abort it
system.abortJob(a.id);
}000382128

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.