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

Test Class for a Apex Scheduler Class
hi I have a ApexScheduler Class which need to be test inorder to
deploy can anybody suggest me the way to achieve it to get the
coverage. I am posting the code below
global class ScheduleTerritoryInactiveMemberCheck implements Schedulable { global void execute(SchedulableContext SC) { TerritoryInactiveMemberCheck bcc = new TerritoryInactiveMemberCheck(); bcc.query = 'select id,name from territory'; Database.executeBatch(bcc,200); } }
cheers,
naga
ScheduleTerritoryInactiveMemberCheck sh1 = new ScheduleTerritoryInactiveMemberCheck();
String sch = '0 0 23 * * ?'; system.schedule('Test Territory Check', sch, sh1); Test.stopTest(); }All Answers
Have you read the documentation?
http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#CSHID=apex_scheduler.htm|StartTopic=Content%2Fapex_scheduler.htm|SkinName=webhelp
offcourse i have read the documentation but still i didn't get it. I am looking for examples similar to my scenario
ScheduleTerritoryInactiveMemberCheck sh1 = new ScheduleTerritoryInactiveMemberCheck();
String sch = '0 0 23 * * ?'; system.schedule('Test Territory Check', sch, sh1); Test.stopTest(); }Thanks British i have tried your code its giving me an Test failure saying
System.StringException: Unexpected end of Expression
at line
hi British got it it was my bad with the spacings its working i appriciate your help.
Just to confirm - you created this as a new method in the Scheduleable class?
I pretty much just cut and pasted it from my own class, so not sure why it is failing - try changing the job name?
Hi can u send me the whole code.bcz i also tried but its not working
Hey , gr8 man thanks a lot for Post this code
Hi,
,
this is my code:
global class ScheduledApex implements Schedulable {
public static String CRON_EXP = '0 0 0 3 9 ? 2022';
global void execute(SchedulableContext ctx) {
List <cd__c> ccdl = [select Date__c,Document_Count__c,Subsidiary__c, Subsidiary__r.Country__c from cd__c where Date__c=:system.today()];
Set <String> country= new Set<string>();
for (cd__c cc:ccdl){
country.add(cc.Subsidiary__r.country__c);
}
List<Subsidiary__c>sub=[select id, country__c from Subsidiary__c];
List<cd__c>insertLog=new List<cd__c>();
for (Subsidiary__c s: sub) {
if(!country.contains(s.country__c)){
cd__c cclog= new cd__c(
Date__c=system.today(),
Document_Count__c=0,
subsidiary__c=s.id,
Risk_Domain_Name__c=s.country__c
);
insertLog.add(cclog);
}
}
insert insertLog;
}
}
I tried your test class:
@istest
public static TestScheduled void testschedule() {
Test.StartTest();
ScheduledApex sh1 = new ScheduledApex();
String sch = '0 0 23 * * ?';
system.schedule('Test check', sch, sh1);
Test.stopTest();
}
I get error message like this - Error: Compile Error: unexpected token: 'TestScheduled' at line 3 column 14
Please help me in resolving this.
Thanks in advance !
I think your syntax is slighty wrong
Try changing this
public static TestScheduled void testschedule() {
@istest
public static void testschedule() {
Test.StartTest();
ScheduledApex sh1 = new ScheduledApex();
String sch = '0 0 23 * * ?';
system.schedule('Test check', sch, sh1);
Test.stopTest();
}
global class AccountRevenueUpdateYTDCalculation_AC implements Schedulable{
global void execute(SchedulableContext SC) {
AccountRevenueUpdate_AC ar = new AccountRevenueUpdate_AC();
ar.submitYTDCalculation();
ar.calculateReportData();
}
}
You can also use this code for quick testing as an anonymus apex.
There it will look like:
global class AgentPointCallOutClassScehdule implements Schedulable {
global void execute(SchedulableContext ctx){
AgentPointCallOutClass apPropImport = new AgentPointCallOutClass();
Database.executeBatch(apPropImport, 100);
}
}
What is the test class for this scheduler class?
public with sharing class TimeZoneRoute implements Schedulable{
public void execute(SchedulableContext sc) {
TimeTest newBatch = new TimeTest('Pacific Standard Time GMT -8:00');
database.executeBatch(newBatch);
}
}
Thanks in advance.