///***Apex の一括処理クラス***
global class RenewContractsBatch implements Database.Batchable<SObject>, Database.Stateful {
global Integer recordsProcessed = 0;
global Database.QueryLocator start(Database.BatchableContext bc){
return Database.getQueryLocator(
//更新を設定するレコードの条件をここに入力します。
'SELECT SBQQ__RenewalForecast__c, SBQQ__RenewalQuoted__c, Id FROM Contract WHERE SBQQ__RenewalForecast__c = FALSE AND SBQQ__RenewalQuoted__c = FALSE'
);
}
global void execute(Database.BatchableContext bc, List<Contract> scope){
for(Contract contract:scope){
contract.SBQQ__RenewalForecast__c = TRUE;
recordsProcessed = recordsProcessed + 1;
}
update scope;
}
global void finish(Database.BatchableContext bc){
// この一括処理ジョブを表す AsyncApexJob の ID を
// Database.BatchableContext から取得します。
// AsyncApexJob オブジェクトを照会して現在のジョブの情報を取得します。
AsyncApexJob a = [SELECT Id, Status, NumberOfErrors, JobItemsProcessed,
TotalJobItems, CreatedBy.Email
FROM AsyncApexJob WHERE Id =
:BC.getJobId()];
// 任意:Apex ジョブの送信者にジョブの完了を通知するメールを送信します。
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {a.CreatedBy.Email};
mail.setToAddresses(toAddresses);
mail.setSubject('Contract Renewal Batch ' + a.Status);
mail.setPlainTextBody
('The batch Apex job processed ' + a.TotalJobItems +
' batches with '+ a.NumberOfErrors + ' failures.');
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
}
//***Schedulable Apex クラス***
global class RenewSchedule implements Schedulable {
global void execute(SchedulableContext ctx) {
RenewContractsBatch batchObject = new RenewContractsBatch();
Id batchId = Database.executeBatch(batchObject, 1);
}
}
//***Scheduled Apex の実行を設定するための匿名 Apex***
RenewSchedule c = new RenewSchedule();
String sch0 = '0 0 * * * ?';
System.schedule('Renew Contracts 0', sch0, c);
String sch1 = '0 10 * * * ?';
System.schedule('Renew Contracts 10', sch1, c);
String sch2 = '0 20 * * * ?';
System.schedule('Renew Contracts 20', sch2, c);
String sch3 = '0 30 * * * ?';
System.schedule('Renew Contracts 30', sch3, c);
String sch4 = '0 40 * * * ?';
System.schedule('Renew Contracts 40', sch4, c);
String sch5 = '0 50 * * * ?';
System.schedule('Renew Contracts 50', sch5, c);
000383568

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.