///***Batch Apex Class***
global class RenewContractsBatch implements Database.Batchable<SObject>, Database.Stateful {
global Integer recordsProcessed = 0;
global Database.QueryLocator start(Database.BatchableContext bc){
return Database.getQueryLocator(
//This is where you input the conditions for the records which you wish to set renewal for
'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){
// 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()];
// OPTIONAL: Send an email to the Apex job's submitter notifying of job completion.
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 Class***
global class RenewSchedule implements Schedulable {
global void execute(SchedulableContext ctx) {
RenewContractsBatch batchObject = new RenewContractsBatch();
Id batchId = Database.executeBatch(batchObject, 1);
}
}
//***Anonymous Apex to Set Up Scheduled Apex Execution***
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.