+ Start a Discussion
yaramareddy radhikayaramareddy radhika 

how to Refer a class related email service in finish method of batch Apex with out writing entire to send acknowledgement to email ?

Best Answer chosen by yaramareddy radhika
Akhil AnilAkhil Anil
Hi yaramareddy,

You can call your email class in the finish method like this. If the method in the email service class is static then you call it like this.
 
public MyBatch implements Database.Batchable<SObject> {

    ...

    public void finish(Database.BatchableContext context) {
        EmailClass.sendEmail();
    }
}
If the method in the emiail service class is non static then you call it like this
 
public MyBatch implements Database.Batchable<SObject> {

    ...

    public void finish(Database.BatchableContext context) {
        EmailClass c = new EmailClass();  
        c.sendEmail();
    }
}

Kindly mark it as an answer if that works !
 

All Answers

Akhil AnilAkhil Anil
Hi yaramareddy,

You can call your email class in the finish method like this. If the method in the email service class is static then you call it like this.
 
public MyBatch implements Database.Batchable<SObject> {

    ...

    public void finish(Database.BatchableContext context) {
        EmailClass.sendEmail();
    }
}
If the method in the emiail service class is non static then you call it like this
 
public MyBatch implements Database.Batchable<SObject> {

    ...

    public void finish(Database.BatchableContext context) {
        EmailClass c = new EmailClass();  
        c.sendEmail();
    }
}

Kindly mark it as an answer if that works !
 
This was selected as the best answer
yaramareddy radhikayaramareddy radhika
thank you, its really help full
 
yaramareddy radhikayaramareddy radhika
And one more Dought,
How can I refer BacthApex class in execute method of SheduleApex class?