You need to sign in to do that
Don't have an account?
Nagarjuna Reddy.P
Email from batch apex
Hello Everyone,
I just need to send email from finish method
ple see my example code
global class batchExample implements Database.Batchable<sObject> {
global Database.QueryLocator start( Database.BatchableContext BC ) {
String query = 'SELECT Id,Name,email FROM contact';
return Database.getQueryLocator( query );
}
global void execute( Database.BatchableContext BC, List< Contact> scope ) {
for ( Contact c : scope ){
if(c.mailingCountry = = 'US')
{
c.Name = c.Name + 'from US';
}
}
update scope;
}
global void finish( Database.BatchableContext BC ) {
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
-------------------------------------------------
mail.setToAddresses(email);
}
}
Here I need to send email to contacts owner and email field of contacts processed in execute()
So how do i get these email ids
Do i need to write SOQL query to get email ids, any guidance is much appreciated.
Thank you all
I just need to send email from finish method
ple see my example code
global class batchExample implements Database.Batchable<sObject> {
global Database.QueryLocator start( Database.BatchableContext BC ) {
String query = 'SELECT Id,Name,email FROM contact';
return Database.getQueryLocator( query );
}
global void execute( Database.BatchableContext BC, List< Contact> scope ) {
for ( Contact c : scope ){
if(c.mailingCountry = = 'US')
{
c.Name = c.Name + 'from US';
}
}
update scope;
}
global void finish( Database.BatchableContext BC ) {
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
-------------------------------------------------
mail.setToAddresses(email);
}
}
Here I need to send email to contacts owner and email field of contacts processed in execute()
So how do i get these email ids
Do i need to write SOQL query to get email ids, any guidance is much appreciated.
Thank you all
Below is the snippet for the finish method.
Thanks,