+ Start a Discussion
Brad007Brad007 

Test class for scheduler class

Can some one please tell me how to write a Unit test class for the scheduler class below please.

Should i seperate class or can i write it in the same class with @IsTest notation. 

 

 

global class HF_Survey_OneMonth Implements Schedulable 
{
    
    global void execute(SchedulableContext sc)
    {
        sendSurvey();
    }
    
    
    
    public void SendSurvey()
    {
         // Get the most recently created config object.
         Config_Object__c config = [Select HFSurveyCode__c, Survey_Date__C, SOQL_Query__C from Config_Object__C 
                                    where Name ='HostFamily_Survey'];
         List<Opportunity> oppList = Database.query(config.SOQL_Query__c);
         
         
             List<Account> accList = new List<Account>();             
                   for(Opportunity opp:oppList)
                     {
                        if(opp.AccountId!= null)
                        {
                          Account acc = opp.Account;
                          if(acc.Survey_Code__c != String.valueOf(config.HFSurveyCode__c) || acc.Survey_Opp_Id__c != opp.Id)
                           {
                             string oppcode= opp.Id;
                             acc.Survey_Code__c = String.valueOf(config.HFSurveyCode__c); 
                             acc.Survey_Dt__c = config.Survey_Date__c;
                             acc.Survey_Opp_Id__c = oppcode.subString(0,15);
                           }  
                         accList.add(acc); 
                        }
                     }
                update accList;  
                          
     }
  }

 

 

 

tmatthiesentmatthiesen

Take a look at the followind documentation:

http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#StartTopic=Content/apex_scheduler.htm?SearchType=Stem

 

You can assert both the timing and the behavior.