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
VSK98VSK98 

Createdby date becomes null in test class

Hi,
@isTest
 private class sendReminderwgntoemployees_Test{
  Static testmethod void sendReminderwgntoemployees_TestMethod(){
  
  Date td = system.Today();
   User u;
   User thisUser = [SELECT Id FROM User WHERE Id = :UserInfo.getUserId()];
    System.runAs (thisUser) {

            Profile p = [SELECT Id FROM Profile WHERE Name='System Administrator'];
            

            UserRole r = [SELECT Id FROM UserRole WHERE Name=' Admin'];

            u = new User(alias = 'sindu1', email='sandvarma1@gmail.com',

                emailencodingkey='UTF-8', lastname='Smith',

                languagelocalekey='en_US',

                localesidkey='en_US', profileid = p.Id, userroleid = r.Id,

                timezonesidkey='America/Chicago',
                username='sandvarma1@gmail.com');

            insert u;
    }  
 recordtype rt=[select id from recordtype where DeveloperName = 'Employee'];
        Contact con=WCT_UtilTestDataCreation.createEmployee(rt.id);
       // con.CreatedDate = td;
        insert con;
        list<_Wage_Notice__c> lstwgn = new list<_Wage_Notice__c>();
        _Wage_Notice__cwgn = new _Wage_Notice__c();
        wgn._Related_To__c = con.id;
        wgn.WTPAA_Status__c = 'sent';
    
      
       lstwgn.add(wgn);
        insert lstwgn;
        system.debug('created by user' +lstwgn[0].createdby);
        system.debug('size********' +lstwgn.size());
        system.debug('value of the status' +lstwgn[0].WTPAA_Status__c);
        system.assertEquals('sent', lstwgn[0].WTPAA_Status__c );
David Holland 6David Holland 6
Siva

Could you tell us what is failing in this or what your problem is?

Many thanks
VSK98VSK98
Hi David,

.
When i check this line system.debug('created by user' +lstwgn[0].createdby);  in debug ............I have been getting null......
Based on the Createddate of Wagenotice record ..........i am quering in batch class............So my test class not covered the execute method due to no records met in queried in batch class 

Thanks
Siv