function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
karthikeya 2karthikeya 2 

Test Class wanted?

Hi all,
i am not getting to write the test class for the following code can any one help me?

global class Wct_OfferPendingforAnalyst implements Database.Batchable<sObject>,Schedulable{

    global void execute(SchedulableContext SC) {
        Wct_OfferApproval_ConsolidatedEmail batch = new Wct_OfferApproval_ConsolidatedEmail();
        ID batchprocessid = Database.executeBatch(batch,100); 
    }
    
    global Database.QueryLocator start(Database.BatchableContext BC)
    {
        String query = 'SELECT Id,Name,Owner.Email,WCT_Candidate_Email__c,WCT_RMS_ID__c,WCT_Full_Name__c,WCT_status__c,WCT_AgentState_Time__c FROM WCT_Offer__c where WCT_status__c IN (\'Offer to Be Extended\', \'Draft in Progress\', \'Returned for Revisions\') and owner.email IN (\'kvalakonda@deloitte.com\',\'rpiramanayagam@deloitte.com\') and WCT_AgentState_Time__c != null '; //owner.email != null'
        return Database.getQueryLocator(query);
    }

    global void execute(Database.BatchableContext BC, List<WCT_Offer__c> listofferRecords)
    {
        set<string> setRecEmails = new set<string>();
        map<string,string> RecTeamEmails = new map<string,string>();
        Map<String, List<WCT_Offer__c>> recOffers = new Map<String, List<WCT_Offer__c>>(); 
        Decimal seconds;
        Decimal hrs;
        
        for(WCT_Offer__c offerRecord : listofferRecords) {
             seconds = BusinessHours.diff(Label.WCT_Default_Business_Hours_ID, offerRecord.WCT_AgentState_Time__c, System.now())/ 1000;
             hrs = seconds / 3600;
             if(hrs > 4) {
                setRecEmails.add(offerRecord.Owner.Email);
                List<WCT_Offer__c> offerList = recOffers.get(offerRecord.Owner.Email);
                if(offerList == null) {
                    offerList = new List<WCT_Offer__c>();
                } 
                offerList.add(offerRecord);
                recOffers.put(offerRecord.Owner.Email,offerList);
            }
        }
        
        String strEmailTop ='';
        String strEmailBody ='';
        String strEmailBottom ='';
        
        strEmailTop  += '<!DOCTYPE html>';
        strEmailTop  += '<html> <head> <style>';
        strEmailTop  += 'table,th,td';
        strEmailTop  += '{ border: 1px solid black; border-collapse:collapse; }, th,td';
        strEmailTop  += ' { padding:5px; }';
        strEmailTop  += '</style> </head> <body> <br> Dear Recruiter,<br> <br>';
        strEmailTop  += 'Offer Letter(s) are pending for more than 4 Hours.<br> <br> <br> <table> <thead>';
        strEmailTop  += ' <tr> <th>Offer Name</th> <th>Candidate Name</th> <th>RMS ID</th> <th>Candidate Email</th> <th>Status</th> <th>Offer letter link</th>';
        strEmailTop  += '</tr> </thead> <tbody>';
        
        strEmailBottom += '</tbody> </table> <br> Thank you,<br> Deloitte Recruting.<br> </body> </html>';
        
        for(string strRecEmail: recOffers.keyset()) {
            strEmailBody ='';
            for(WCT_Offer__c offerRecord : recOffers.get(strRecEmail)) {
            
                    strEmailBody += '<tr> <td>'+offerRecord.Name+'</td> <td>'+offerRecord.WCT_full_Name__c+'</td><td>'+offerRecord.WCT_RMS_ID__c+'</td><td>'+offerRecord.WCT_Candidate_Email__c+'</td>';
                    strEmailBody += '<td>'+offerRecord.WCT_status__c+'</td><td><a href='+Label.BaseURL+'/'+offerRecord.id+'>URL</a></td></tr>';
            }
            
            list<string> ToEmailAddress = new list<string>();
            
            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
            ToEmailAddress.add(strRecEmail);
            mail.settoAddresses(ToEmailAddress);
            mail.setSubject('Immediate Action: Offer Letter(s) are pending');
            mail.setHTMLBody(strEmailTop+strEmailBody+strEmailBottom);
            mail.setSaveAsActivity(false);
            if(ToEmailAddress != null){
                Messaging.sendEmail(new Messaging.SingleEmailMessage [] {mail});
            }
        }
    }

    global void finish(Database.BatchableContext BC){
      
    }
}
Ajay Nagar 7Ajay Nagar 7
http://www.cloudforce4u.com/2013/07/test-class-for-batch-apex.html
http://learningthecloudway.blogspot.in/2014/02/how-to-write-test-class-for-batch-apex.html
http://www.infallibletechie.com/2013/09/test-class-for-batch-apex-in-salesforce.html
Above links may help you.