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
Ermin TsikkosErmin Tsikkos 

Apex class scheduler

I have a scheduler that works in the sandbox environment but not working in production and reason why.  is there any possiblity to view the logs
Amit Chaudhary 8Amit Chaudhary 8
Can you please post your code so that we can look into same ?
Ermin TsikkosErmin Tsikkos
Thanks for Your reply ...
Description : scheduled Apex class copies the entire record set from App_Dev table and moves it to App_Dev_Log table .

Apex Class :
-----------------
public class appdevDailySnapShot implements Schedulable{
    public List<App_Dev__c> ac {set;get;}
    
    // implement the Schedulable interface
    public void execute(SchedulableContext con) {
        execute();
    }
    
    @TestVisible
    private void execute(){
        List<App_Dev_Log__c> lstADL = new List<App_Dev_Log__c>();
        try
        {               
           ac=[select Name,Assigned_To__c,Category__c,Completed_date__c,Effort_Hrs__c,Environment__c,Expected_QA_Date__c,In_Progress_Date__c,Old_Create_Date__c,Old_Request__c,On_Hold_date__c,Priority__c,Production_Release_Date__c,Project__c,Ready_for_Production_Release__c,Released_in_QA_Date__c,Released_in_UAT_date__c,Requested_QA_Release_Date__c,Status__c,SVN_update__c,Type__c,Unit_testing_DEV__c,Verified_in_Production__c,Verified_in_QA_Date__c,Verified_in_UAT_date__c from App_Dev__c];            
            for(App_Dev__c adc : ac)
            {
                App_Dev_Log__c AL = new App_Dev_Log__c();
                AL.AD_Request_No__c = adc.Name;
                AL.Assigned_To__c = adc.Assigned_To__c;
                AL.Category__c = adc.Category__c;
                AL.Completed_date__c = adc.Completed_date__c;
                AL.Effort_Hrs__c = adc.Effort_Hrs__c;
                AL.Environment__c = adc.Environment__c;
                AL.Expected_QA_Date__c = adc.Expected_QA_Date__c;
                AL.In_Progress_Date__c = adc.In_Progress_Date__c;
                AL.Old_Create_Date__c = adc.Old_Create_Date__c;
                AL.Old_Request__c = adc.Old_Request__c;
                AL.On_Hold_date__c = adc.On_Hold_date__c;
                AL.Priority__c = adc.Priority__c;
                AL.Production_Release_Date__c = adc.Production_Release_Date__c;
                AL.Project__c = adc.Project__c;
                AL.Ready_for_Production_Release__c = adc.Ready_for_Production_Release__c;
                AL.Released_in_QA_Date__c = adc.Released_in_QA_Date__c;
                AL.Released_in_UAT_date__c = adc.Released_in_UAT_date__c;
                AL.Requested_QA_Release_Date__c = adc.Requested_QA_Release_Date__c;
                AL.Status__c = adc.Status__c;
                AL.SVN_update__c = adc.SVN_update__c;
                AL.Type__c = adc.Type__c;
                AL.Unit_testing_DEV__c = adc.Unit_testing_DEV__c;
                AL.Verified_in_Production__c = adc.Verified_in_Production__c;
                AL.Verified_in_QA_Date__c = adc.Verified_in_QA_Date__c;
                AL.Verified_in_UAT_date__c = adc.Verified_in_UAT_date__c;
                AL.Snapshot_Date__c = date.today();
                AL.Snapshot_Time__c = datetime.now();
                lstADL.add(AL);
            }        
            insert(lstADL);
        }
        catch(Exception pEx){
            System.debug('**** Exception Inserting in APP_DEV_Log ****');
            System.debug(pEx.getMessage());
        }
        finally{
            lstADL.clear();
            lstADL = null;
        }
    }   
}

------------------------
Apex Test Class :
------------------------
@istest
public class appdevDailySnapShot_Test {
    
    static void addTestData(){
        App_Dev__c ad = new App_Dev__c();
        ad.Type__c = 'Support';
        ad.Category__c = 'appdev-SnapshotTest';
        // maybe set other properties?
        insert ad;
    }
    static testMethod void testCanBeScheduled() {
        addTestData(); // insert test data before running cron job
        Test.startTest();
        Datetime dt2 = Datetime.now().addMinutes(1);
        String CRON_EXP2 = '0 '+ dt2.minute() + ' * ' + dt2.day() + ' ' + dt2.month() + ' ? ' + dt2.year();
        Id jobId = System.schedule('AppDev Daily Snapshot - Test1', CRON_EXP2, new appdevDailySnapShot());
        Test.stopTest();
        System.assertNotEquals(null, jobId);
    }
    static testMethod void testCheckResults() {
        addTestData(); // insert test data before running cron job
        Test.startTest();
        appdevDailySnapShot aObj = new appdevDailySnapShot();
        aObj.execute();
        Test.stopTest();

        // query App_Dev_Log__c for expected results
        List<App_Dev_Log__c> lstADL = [select AD_Request_No__c from App_Dev_Log__c];
        System.assertEquals(1, aObj.ac.size());
        System.assertEquals(1, lstADL.size());
        System.assertEquals(aObj.ac[0].Name, lstADL[0].AD_Request_No__c);
        // check additional properties here (must add to above query)
    }
}

This runs in sandbox and on migrating to live environment not a single record is populated in App_Dev_Log table
Could you please help me on this ..?..