You need to sign in to do that
Don't have an account?

Help writing a test class for Scheduler Class
Hi I am new to Apex code development. I am really unsure about how to write test class here. Can any one please help .
Here is the scheduler class it works fine
But to the test class i have written the code coverage says it covered 0 lines .And how do i deply it to production. Please help. Here is the test class i have written
@isTest
private class test_Config_Survey {
static testMethod void myUnitTest() {
// TO DO: implement unit test
//Test.startTest();
Config_Object__c config = [Select HFSurveyCode__c, Survey_Date__C, SOQL_Query__C from Config_Object__C
where Name ='HostFamily_Survey' limit 1];
for(Opportunity oppList: [Select o.Id, o.Account.Id, o.AccountId, o.Account.Survey_Opp_Id__c, o.Account.Survey_Dt__c, o.Account.Survey_Code__c, o.Account.Name
From Opportunity o
where o.StageName='Active'
AND o.Placmnt_Start_Date_Arrive__c < Last_N_days :30
AND o.Placmnt_Start_Date_Arrive__c = Last_N_days :60 limit 1])
Account acclist = new Account();
acclist = oppList.Account;
if(acclist.Survey_Code__c !=config.HFSurveyCode__c || acclist.Survey_Opp_Id__c != '0064000000CsXem')
{
acclist.Survey_Code__c=config.HFSurveyCode__c ;
acclist.Survey_Opp_Id__c = '0064000000CsXem';
acclist.Survey_Dt__c=Date.today();
}
update acclist;
//Test.stopTest();
}
}
Brad007
First off, take a look at the APEX Code Developer's Guide under the heading 'testing the Apex Scheduler'
You need to:
* Uncomment out the Test.startTest(), Test.stopTest(). These tell the testmethod that schedule should run. Do asserts after the the Test.stopTest().
* Use the System.Schedule method in your testMethod to cause the schedulable class to be executed.
Best practices also suggest removing the sendSurvey() method out to a separate class that you can test independently without worrying about the scheduler logic
As for deployment, you deploy the class like any other APEX class. Some nuances:
* If you already have the class running in PROD in a scheduled state, you'll need to delete the schedule before deploying; then reschedule
* If you need to schedule more often than weekly, then you'll need to execute anonymous APEX in the System Log with a custom CRON setting for example, daily. Otherwise, you can use the Schedule APEX button in Setup | Develop | Apex Classes
Hi Eric,
Thank yo for your response.
so now i understand that i dont have to use global and implement schedulable interface, the other option is to write a class and implement what i need and through SFDC UI schedule the class to run for a particular timing is what your suggesting. Is it corect.
Brad007
Sorry for the very late reply
1. If you want an APEX class to execute on a schedule, it needs to implement the Schedulable interface
2. If it implements the Schedualbel interface, you can start the schedule running in several ways. Using out-of-the-box SFDC , you can