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

Apex Scheduler test class
Hi, I have Scheduler class which is not initiating any other class but has a static method within. I had to build this class such a way as i had to make a apex call out and which needs to static. So my scheduler class works fine but i need a head start on how i can test the rest of the lines of code please check below for code and help me give a head start. /*The scheduler class fires hourly for the AP Files*/ global class APFiles_ScheduledHourlyRun implements Schedulable { global void execute(SchedulableContext sc) { APFilesMissing(); } @future(callout=true) public static void APFilesMissing() { // Exception log to capture various kind of errors as unable to make callouts, bad data or read time out issues. List errors = new List(); Datetime RuntimeCode = Datetime.newInstance(date.today(),time.newInstance(1, 11, 11, 0)); try { string ServiceResult = ''; // Creates list for Available Aupairs List APFiles = [Select a.Id ,a.Au_Pair__c,a.AP_Folder_Name__c, a.Photo4__c, a.Photo3__c, a.Photo2__c, a.Photo1__c, a.IsExist_Photo4__c, a.IsExist_Photo3__c, a.IsExist_Photo2__c, a.IsExist_Photo1__c,a.Au_Pair__r.Id,a.Au_Pair__r.AP_Status__c,a.Au_Pair__r.Record_Type_Name__c From AP_Application__c a where a.Au_Pair__r.AP_Status__c ='Available' AND a.Au_Pair__r.Record_Type_Name__c= 'Au Pair']; // Root of Xml string string XmlString = ''; //Create Xml record element for every APPhoto file with IsPhotoExist as false for(AP_Application__c APAppObj: APFiles) { if(APAppObj.IsExist_Photo1__c == false) { XmlString += ''; XmlString += ''+APAppObj.Id+''; XmlString += ''+APAppObj.Au_Pair__c+''; XmlString += ''+APAppObj.Photo1__c+''; XmlString += ''; } if(APAppObj.IsExist_Photo2__c == false ) { XmlString += ''; XmlString += ''+APAppObj.Id+''; XmlString += ''+APAppObj.Au_Pair__c+''; XmlString += ''+APAppObj.Photo2__c+''; XmlString += ''; } if(APAppObj.IsExist_Photo3__c == false ) { XmlString += ''; XmlString += ''+APAppObj.Id+''; XmlString += ''+APAppObj.Au_Pair__c+''; XmlString += ''+APAppObj.Photo3__c+''; XmlString += ''; } if(APAppObj.IsExist_Photo4__c == false ) { XmlString += ''; XmlString += ''+APAppObj.Id+''; XmlString += ''+APAppObj.Au_Pair__c+''; XmlString += ''+APAppObj.Photo4__c+''; XmlString += ''; } } //Close root Xml XmlString += ''; System.debug('XML:' +XmlString); // Create WSDL Stub for Call out GAPOrg.AjaxSoap servicestub = new GAPOrg.AjaxSoap(); servicestub.timeout_x = 9000; ServiceResult = servicestub.GAPAPFiles(XmlString); //System.debug('XmlResultfromService:' +xmldata); //Retrive the values from Xml using DOM class List Files = new List(); Dom.Document docx = new Dom.Document(); docx.load(ServiceResult); Dom.Xmlnode xroot = docx.getRootElement(); Dom.Xmlnode[] xrec = xroot.getChildElements(); for(Dom.Xmlnode child : xrec) { Files__c file = new Files__c(); for(Dom.Xmlnode node : child.getchildren()) { if(node.getName() == 'ApplicationId') { //system.debug('ApplicationId:' +node.gettext()); file.AP_Application__c = node.gettext(); } if(node.getName() == 'APID') { //system.debug('APID:' +node.gettext()); file.Contact__c = node.gettext(); } if(node.getName() == 'Filepath') { String[] path = node.gettext().split('/'); string filepath = +path[4]+'/'+path[5]+'/'+path[6]+'/'+path[7]; system.debug('Filepath:'+path[4]+'/'+path[5]+'/'+path[6]+'/'+path[7]); //system.debug('Filepath:' +node.gettext()); file.Path__c = filepath; } } Files.add(file); system.debug(File); } insert Files; } catch (Exception e) { Exception_Log__c ex = new Exception_Log__c(); ex.Exception_Code__c =''; ex.Error_Message__c = e.getMessage(); errors.add(ex); System.debug(e.getMessage()); } List nice = BusinessExceptionServices.SaveLogEntries(null,errors); errors.clear(); } } Thank in advance!
Your class is not clear. so I will provide you an example apex scheduler class and the test class of it.
//scheduler class
//test class
You need to set the scheduler in test class
Refer : http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_scheduler.htm
If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.