///***Clase de Apex por lotes***
global class RenewContractsBatch implements Database.Batchable<SObject>, Database.Stateful {
global Integer recordsProcessed = 0;
global Database.QueryLocator start(Database.BatchableContext bc){
return Database.getQueryLocator(
//Aquí es donde debe introducir las condiciones para los registros en los que quiere establecer la renovación.
'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){
// Obtenga el Id. del AsyncApexJob que representa este trabajo por lotes.
// from Database.BatchableContext.
// Consulte el objeto AsyncApexJob para recuperar la información del trabajo actual.
AsyncApexJob a = [SELECT Id, Status, NumberOfErrors, JobItemsProcessed,
TotalJobItems, CreatedBy.Email
FROM AsyncApexJob WHERE Id =
:BC.getJobId()];
// OPCIONAL: Notifique por correo electrónico a quien envió el trabajo de Apex sobre el trabajo terminado.
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 });
}
}
//***Clase de Apex programable***
global class RenewSchedule implements Schedulable {
global void execute(SchedulableContext ctx) {
RenewContractsBatch batchObject = new RenewContractsBatch();
Id batchId = Database.executeBatch(batchObject, 1);
}
}
//***Apex anónimo para configurar la ejecución programada de 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.