+ Start a Discussion
ChinnoduChinnodu 

How to send an email to user , whenever inserting or updating records using batch apex

Hi Experts,

Please let me know whenever i am  inserting or updating records on Account object using batch apex after complition of this, i will send an email to users , how to write the example logic ,,request you  needful.

Thanks,
Chinna
Anil JAdhav 14Anil JAdhav 14
Hi Chinna,

Just write the below code in Batch Finish method.
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
            email.setToAddresses(new String[] {give email here});
            email.setTargetObjectId(ta.OwnerId);
            email.setTemplateId(emailTemplate.Id);
            Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});

Regards,
Anil​​​​​​​