You need to sign in to do that
Don't have an account?
sfdc007
Test class for Batch class help needed
Hi,
I am trying to write test class for the below batch class , Kindly help me how to write the test class for it please
Kindly help me pls
Thanks in Advance
I am trying to write test class for the below batch class , Kindly help me how to write the test class for it please
MY BATCH CLASS : global class CROBatchController implements Database.Batchable<sObject> { global string strBusHrId; global Database.QueryLocator start(Database.BatchableContext BC) { BusinessHours bh = [SELECT Id, Name FROM BusinessHours WHERE Name = 'Defend']; if(bh != null){ strBusHrId = bh.Id; } // SOQL Query to fetch the values of hours , minutes and days String query = 'select Id, Status__c,CreatedDate From Team_Form__c where Status__c = \'New\' and Engagement_Team__r.Initial__c = \'Defend\''; return Database.getQueryLocator(query); } global void execute(Database.BatchableContext BC, List<Team_Form__c> lstTF) { system.debug('strBusHrId=>'+strBusHrId); List<Id> lstTFIds = new List<Id>(); map<Id,DateTime>tfCDtMap = new map<Id,DateTime>(); for(Team_Form__c objTF: lstTF){ lstTFIds.add(objTF.Id); } for(Team_Form__History objTFHis:[select Id, CreatedDate, NewValue,OldValue,ParentId from Team_Form__History where Field = 'Status__c' and ParentId in :lstTFIds Order By CreatedDate ASC]){ if(string.valueof(objTFHis.NewValue) == 'New'){ tfCDtMap.put(objTFHis.ParentId,objTFHis.CreatedDate); } } Datetime startDate, endDate; endDate = System.Datetime.now(); string subject; map <Id, String> chatterTextMap = new map <Id, String> (); map <Id, set <Id>> mentionIdMap = new map <Id, set <Id>> (); List<Id> lsmentionId = new List<Id>(); for(Team_Group_Member__c objTGM :[select Id, Engagement_Team__r.Initial__c,User__c From Team_Group_Member__c where User_Role__c = 'Super User' and Engagement_Team__r.Initial__c = 'Defend']){ lsmentionId.add(objTGM.User__c); } for(Team_Form__c objTF: lstTF) { if(tfCDtMap.get(objTF.Id) != null){ startDate = tfCDtMap.get(objTF.Id); }else{ startDate = objTF.Createddate; } long businessMillisecondsDiff = BusinessHours.diff(strBusHrId, startDate, endDate); long millitoHrs = businessMillisecondsDiff/3600000; if(millitoHrs >= 48){ subject = 'TF is in \'New\' status for more than 48hrs'; chatterTextMap.put(objTF.Id,Subject); mentionIdMap.put(objTF.Id,new set <Id>(lsmentionId)); if(chatterTextMap.size()>0){ CommunityUtility.postCustomFeedItem (mentionIdMap, chatterTextMap, 'AllUsers'); } } } } global void finish(Database.BatchableContext BC) { } }
Kindly help me pls
Thanks in Advance
https://developer.salesforce.com/docs/atlas.en-us.apex_workbook.meta/apex_workbook/apex_batch_2.htm
Create your data in the following snippt : Regards
Tej Pal Kumawat
Skype : tejpalkumawat1991
If this answers your question mark Best Answer it as solution and then hit Like!
System.NullPointerException: Business Hours Id cannot be null
Kindly help me what is the issue here pls
Thanks
Try with this : http://salesforce.stackexchange.com/questions/33580/set-business-hours-in-apex-test-code
Regards
Tej Pal Kumawat
Skype : tejpalkumawat1991
If this answers your question mark Best Answer it as solution and then hit Like!
If this answers your question, unlike or remove a Best Answer from someone who makes demands on every post.