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

Scheduled Apex Working in Sandbox but not in Production


I've created a scheduled Apex class shown below: 

global class scheduleContractTriggers implements Schedulable {
    global void execute(SchedulableContext SC) {
        List <Contract> contracts = [SELECT OwnerId, Last_Scheduled_Run__c FROM Contract];         
        for(Contract c : contracts){
            if(c.OwnerId != null)
                c.Last_Scheduled_Run__c =;
That updates all Contracts and sets a custom field, Last Scheduled Run, to today's date. This scheduled class then triggers an "after update" trigger on Contracts seen below: 
trigger cloneExpiringContract on Contract (after insert, after update) { 
    List<Contract> contractsToClone = [SELECT Id, Status, Auto_Renew__c, EndDate FROM Contract];
    List<Contract> newContracts = new list<Contract>(); 
    for (Contract c : {
        if ((c.Auto_Renew__c == TRUE) && (c.EndDate =={ 
            Contract clonedContract = new Contract();
            //Contract Details
            clonedContract.Owner = c.Owner; 
            clonedContract.AccountID = c.AccountID;
            clonedContract.Opportunity_Name__c = c.Opportunity_Name__c;
            clonedContract.Status = 'Draft'; //have to save it as a draft first 
            clonedContract.Contract_Type__c = c.Contract_Type__c; 
            clonedContract.Co_Marketing_Opportunities__c = c.Co_Marketing_Opportunities__c; 
            clonedContract.Previous_Contract__c = c.Id; 
           	Date newStartDate = c.EndDate.addDays(1);
            clonedContract.StartDate = newStartDate;
            clonedContract.ContractTerm = c.ContractTerm;
            clonedContract.Auto_Renew__c = TRUE;
            //License Agreement
            clonedContract.MonthtoMonth__c = c.MonthtoMonth__c; 
            clonedContract.Comments_NDA__c = c.Comments_NDA__c; 
            clonedContract.Type_Mutual_One_Side__c = c.Type_Mutual_One_Side__c;
            clonedContract.Duration__c = c.Duration__c;
            //Signature Information
            clonedContract.CustomerSigned = c.CustomerSigned; 
            clonedContract.CustomerSignedDate = c.CustomerSignedDate; 
            clonedContract.CustomerSignedTitle = c.CustomerSignedTitle;
            clonedContract.CompanySigned = c.CompanySigned;
            clonedContract.CompanySignedDate = c.CompanySignedDate;
insert newContracts;
In Sandbox, the scheduled class was successfully updating the "Last Scheduled Run" field and firing the trigger when applicable. However, when I schedule the class in Production, although it says the scheduled run has succeeded, the "Last Scheduled Run" field is no longer getting populated and therefore the trigger is never fired. 

Any suggestions on why this would be or how to fix this are much appreciated. 
The only thing can think of is that perhaps the OwnerId is not null.
Also can you check if there is Last_Scheduled_Run__c field available on the Contract object? Does it throw any errors?
Also I am a bit concerened on checking your trigger. Is the field ownerid manually populated?
No OwnerID is automatically populated, based on whoever creates the Contract. And I've checked and the Last_Scheduled_Run__C field is available on the Contract object and does not throw any errors when I manually populate it.