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
AnjaneyluAnjaneylu 

Batch apex Single Email Messafging

Global class BatchFirst1 implements database.batchable<sObject>{
    global database.querylocator start(database.batchablecontext BC){
       String acct = 'select id, name from account limit 10';
        return database.getQuerylocator(acct);
}
    global void execute(database.batchablecontext bc, list<account> acct){
    
        for(account acc : acct){
        
            acc.name= acc.name + 'checked';
        }
        update acct;
    }
     global void finish(Database.BatchableContext BC){
     Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
    
          mail.setToAddresses(new String[] {abcd@gmail.com});
       mail.setReplyTo('batch@acme.com');
       mail.setSenderDisplayName('Batch Processing');
        mail.setSubject('Batch Process Completed');
        mail.setPlainTextBody('Batch Process has completed');
 
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
      }
my intention is to send the email after completion of batch class finish method..
here i am getting error like   Error: Compile Error: unexpected token: '@' at line 16 column 58.
Please tell me the solution..
Thanks and regards,
Anji reddy.
Best Answer chosen by Anjaneylu
AshwaniAshwani
You forgot to wrap it with Single Quote:
 
mail.setToAddresses(new String[] { 'abcd@gmail.com' });

 

All Answers

AshwaniAshwani
You forgot to wrap it with Single Quote:
 
mail.setToAddresses(new String[] { 'abcd@gmail.com' });

 
This was selected as the best answer
AnjaneyluAnjaneylu
Thank you Ashwani..
sandeep reddy 37sandeep reddy 37
thats ok but i want take emailid s from batch execuation method which records compleates dml on that records we can perform sent emails