function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Veerendar AellaVeerendar Aella 

When quote status is equal to "ready to price" or "proposed" and quote expiration date is today, move quote status to expired. Need an Apex Scheduler class. Please advice

Hi All,

I want to create a scheduler class. When quote status is equal to "ready to price" or "proposed" and quote expiration date is today, move quote status to expired. Please advice
RKSalesforceRKSalesforce
Hi Veerender,

Please use below batch class to write your logic :
global class updatesQuotesToExpired implements 
    Database.Batchable<sObject>, Database.Stateful {
    
    global Database.QueryLocator start(Database.BatchableContext bc) {
        return Database.getQueryLocator(
            'SELECT ID, Status FROM Quote Where Status = \'Ready to price\' OR Status = \'Proposed\' AND ExpirationDate = TODAY'
        );
    }
    global void execute(Database.BatchableContext bc, List<Account> scope){
        // process each batch of records
        List<Quote> quotesToUpdate = new List<Quote>();
		List<Quote> quotesToProcess = New List<Quote>();
		quotesToProcess = (List<Quote>) scope;
        for (Quote quoteRecord : quotesToProcess) {
            quoteRecord.Status = 'Expired';
			quotesToUpdate.add(quoteRecord);
        }
        update quotesToUpdate;
    }    
    global void finish(Database.BatchableContext bc){
        
    }    
}

Use Bewlo code to create Scheduler class:
global class updatesQuotesToExpiredScheduler implements Schedulable {
   global void execute(SchedulableContext sc) {
      updatesQuotesToExpired b = new updatesQuotesToExpired(); 
      database.executebatch(b);
   }
}


You can schedule your Class from Setup --> Apex Classes --> Click On schedule Apex.

Please mark as best answer if helped.

Regards,
Ramakant