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
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?