• AlpsPSO Community
  • NEWBIE
  • 0 Points
  • Member since 2011

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 8
    Replies

Hello,

 

Can anyone help me in code coverage for the below sample code. Its really urgent for the Production. The code is fine in Sandbox :

 

Main class :

 

/************************************************************************************************************************

 

global class NotificationScheduledFor40Hours implements Schedulable {

//public static String userProfileID = '';

    global void execute(SchedulableContext ctx) {       
      
         sendEmail();
    }
   
    private void sendEmail(){   
           
        for( User  u : [SELECT id,ProfileId,FirstName,Email,Total_hours_of_week__c FROM User WHERE User.Total_hours_of_week__c <: 40.00 limit 1000] ){
       
                String email = u.Email;
                String userProfileID = u.ProfileId;
                String userEmail = u.Email;
        }
    }

}

 

/************************************************************************************************************************

 

Test class as below :

 

 

/************************************************************************************************************************

 @istest
private class EmailTestClass {

static testmethod void EmailTest(){
   
    List<User> userList = new List<User>();
   
    Profile profile = [select id from profile where name='Consultant User'];
    User u = new User(alias = 'cons', email='standarduserEmail@testorg.com',
        emailencodingkey='UTF-8', lastname='nameL', languagelocalekey='en_US',
        localesidkey='en_US', profileid = profile.Id,
        timezonesidkey='America/Los_Angeles', username='standardusername@testorg.com');
   
    insert u;
   
    u.put('FirstName', 'nameF');   
    u.put('Total_hours_of_week__c',10.00);
   
    update u;
   
    userList.add(u);
   
    System.assert(true,userList);
   
    if ( userList.isEmpty()) system.debug('No user found');
   
    else {
   
    System.assert(true,u);
    System.assertEquals(u.FirstName, 'nameF');
    System.assertEquals(u.Email, 'standarduserEmail@testorg.com');
    System.assertEquals(u.ProfileId, '00e80000000l0tQAAQ');
   
    String firstName = u.FirstName;
    String uProfileId = u.ProfileId;
    String email = u.Email;   
   
    System.debug('firstName : ' + firstName);
    System.debug('Profile id : ' + uProfileId);
    System.debug('email : ' + email);
    }
}
}

/************************************************************************************************************************



Please let m eknow hat i am missing.

Hi Everyone,

 

I ma fcaing a surprising issue while saving my apex class scheduled. The code worked great in my sandbox but when i tried to migrate it to production. It didn,t allowed me to save the code.

 

Below is my simple code :

 

global class NotificationScheduledFor40Hours implements Schedulable {

   
        private final List<Id> contactids = new List<Id>();
        private final List<Id> userIds = new List<Id>();
        private final List<User> userList = new List<User>();
        private final List<String> emailAddressList = new List<String>();   
   
        global void execute(SchedulableContext ctx) {
   
        List<User>  u = [SELECT id,ProfileId,FirstName,Email,Total_hours_of_week__c FROM User WHERE User.Total_hours_of_week__c <: 40.00 limit 1000];
       
        if(! u.isEmpty()){
           
            system.debug('u is :: ' + u);

             for(Integer i=0;i<u.size();i++)
             {
                User u1 = u[i];                
                 
                System.debug('u1::' + u1);

            }

      }

 }

}

 

The code is working fine in Sandbox. But for production it start giving error at line - if(! u.isEmpty()){ } and do not reflect any logical calculation. I mean to say i am not able to use any variable attribute inside this - global void execute(SchedulableContext ctx) {} method.

 

Please help me.

 

Hello,

 

Can anyone help me in code coverage for the below sample code. Its really urgent for the Production. The code is fine in Sandbox :

 

Main class :

 

/************************************************************************************************************************

 

global class NotificationScheduledFor40Hours implements Schedulable {

//public static String userProfileID = '';

    global void execute(SchedulableContext ctx) {       
      
         sendEmail();
    }
   
    private void sendEmail(){   
           
        for( User  u : [SELECT id,ProfileId,FirstName,Email,Total_hours_of_week__c FROM User WHERE User.Total_hours_of_week__c <: 40.00 limit 1000] ){
       
                String email = u.Email;
                String userProfileID = u.ProfileId;
                String userEmail = u.Email;
        }
    }

}

 

/************************************************************************************************************************

 

Test class as below :

 

 

/************************************************************************************************************************

 @istest
private class EmailTestClass {

static testmethod void EmailTest(){
   
    List<User> userList = new List<User>();
   
    Profile profile = [select id from profile where name='Consultant User'];
    User u = new User(alias = 'cons', email='standarduserEmail@testorg.com',
        emailencodingkey='UTF-8', lastname='nameL', languagelocalekey='en_US',
        localesidkey='en_US', profileid = profile.Id,
        timezonesidkey='America/Los_Angeles', username='standardusername@testorg.com');
   
    insert u;
   
    u.put('FirstName', 'nameF');   
    u.put('Total_hours_of_week__c',10.00);
   
    update u;
   
    userList.add(u);
   
    System.assert(true,userList);
   
    if ( userList.isEmpty()) system.debug('No user found');
   
    else {
   
    System.assert(true,u);
    System.assertEquals(u.FirstName, 'nameF');
    System.assertEquals(u.Email, 'standarduserEmail@testorg.com');
    System.assertEquals(u.ProfileId, '00e80000000l0tQAAQ');
   
    String firstName = u.FirstName;
    String uProfileId = u.ProfileId;
    String email = u.Email;   
   
    System.debug('firstName : ' + firstName);
    System.debug('Profile id : ' + uProfileId);
    System.debug('email : ' + email);
    }
}
}

/************************************************************************************************************************



Please let m eknow hat i am missing.

Hi Everyone,

 

I ma fcaing a surprising issue while saving my apex class scheduled. The code worked great in my sandbox but when i tried to migrate it to production. It didn,t allowed me to save the code.

 

Below is my simple code :

 

global class NotificationScheduledFor40Hours implements Schedulable {

   
        private final List<Id> contactids = new List<Id>();
        private final List<Id> userIds = new List<Id>();
        private final List<User> userList = new List<User>();
        private final List<String> emailAddressList = new List<String>();   
   
        global void execute(SchedulableContext ctx) {
   
        List<User>  u = [SELECT id,ProfileId,FirstName,Email,Total_hours_of_week__c FROM User WHERE User.Total_hours_of_week__c <: 40.00 limit 1000];
       
        if(! u.isEmpty()){
           
            system.debug('u is :: ' + u);

             for(Integer i=0;i<u.size();i++)
             {
                User u1 = u[i];                
                 
                System.debug('u1::' + u1);

            }

      }

 }

}

 

The code is working fine in Sandbox. But for production it start giving error at line - if(! u.isEmpty()){ } and do not reflect any logical calculation. I mean to say i am not able to use any variable attribute inside this - global void execute(SchedulableContext ctx) {} method.

 

Please help me.