+ Start a Discussion
sfdc007sfdc007 

btach class in test coverage

Hi,

I have a method in my apex class where i am not able to cover , need help on it


public static void sendEmailAfterBatchJob(Database.BatchableContext BC, String jobName)
    {
        if (BC.getJobId() != null)
        {
        AsyncApexJob a = [Select Id, Status, NumberOfErrors, JobItemsProcessed,
                            TotalJobItems, CreatedBy.Email from AsyncApexJob
                        where Id =:BC.getJobId()];
        
        // Send an email to the Apex job's submitter notifying of job completion.         
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        String[] toAddresses = new String[]{};
        toAddresses.add(a.CreatedBy.Email);
        string newaddress = system.label.GSAM_Batch_Email_Notification;
        toAddresses.add(newaddress);
        mail.setToAddresses(toAddresses);
        mail.setSubject(jobName + ' ' + a.Status);
        mail.setPlainTextBody
        (jobName + ' Apex job processed ' + a.TotalJobItems +
        ' batches with '+ a.NumberOfErrors + ' failures.');
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });      
        }
    }



I tried to call controller. methodname() , but not sure about the parameters to pass


Kindly help me pls

Thanks in Advance
an2014an2014
Hello

I created a construction to create an object

Database.QueryLocator QL;
Database.BatchableContext BC;
Bulkclass bc=new BulkClass();

QL=bc.start(BC);
sfdc007sfdc007
Hi,

I tried calling the same way

       Database.QueryLocator QL;
        Database.BatchableContext BC;
        GSAMUtilityClass bc1=new GSAMUtilityClass();
        QL=bc1.sendEmailAfterBatchJob(BC,'test');



but its not saving the class