• Ermin Tsikkos
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 1
    Replies
Hello All ,


I am new to Apex Coding and running in to production issue Scheduled class runs fine in sandbox, deployed successfully with 100% code coverage, but now the job isn't executing in production.  Scheduled with the Schedule Apex tool in UI just as in Sandbox.  The job shows up in Scheduled Jobs but nothing happens, no errors, nothing to see in Apex Jobs.

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)
    }
}
 
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
I have a Schedulableclass which is scheduled to execute every night at 12:00 AM,  here is my class, 


*****
public class appdevDailySnapShot implements Schedulable{
    public List<App_Dev__c> ac {set;get;}    
    public void execute(SchedulableContext con){
        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;
        }
    }   
}

************

here is my test class,  my code coverage is 22%.

@istest
public class appdevDailySnapShot_Test {
    static testMethod void testSample1(){
        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.assert(jobId != null);
    }
    static testMethod void testSample2() {
        Test.startTest();
        Datetime dt = Datetime.now().addMinutes(1);
        appdevDailySnapShot aObj = new appdevDailySnapShot();
        String CRON_EXP = '0 '+ dt.minute() + ' * ' + dt.day() + ' ' + dt.month() + ' ? ' + dt.year();
        String jobId = System.schedule('AppDev Daily Snapshot - Test2', CRON_EXP, aObj);   
        Test.stopTest();
    }



How to increase the code coverage .. Could you guys please help.
 
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