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
naveen kunurunaveen kunuru 

batchupdate is done but i suppose to get mail (no mail)

I UPDATE THE PRICE FIELD AFTER UPDATE I SUPPOSE TO GET MAIL TO MY MAIL ID THE ONE I WROTE IN FINISH METHOD ...CAN ANY ONE HELP ME WATS WRONG WITH  MY FINISH CODE ......

global class emailWhenBatchUpdate Implements DataBase.Batchable<sObject> {
   global Database.QueryLocator start(DataBase.BatchableContext bc)     {
   string obj_query = 'Select Name,Price__c,Quantity__c from Bottle__c';
   return DataBase.getQueryLocator(obj_query);
   }  
   global void execute(DataBase.BatchableContext bc, List<Bottle__c> bottles)    {
   List<Bottle__c> bottleList = New List<Bottle__c>();  
   for(Bottle__c btl : bottles)
   {
    btl.Price__c = btl.Price__c + 100;
    bottleList.add(btl); 
   }
   update bottleList;    
}  
   global void finish(DataBase.BatchableContext bc)   {
   String userName = UserInfo.getUserName();
   String senderName = UserInfo.getFirstName()+ ' ' +UserInfo.getLastName();
   User usr = [Select Email From User Where Username = :userName LIMIT 1];
   String userEmail = usr.Email;      
   Messaging.SingleEmailMessage emailMsg = New Messaging.SingleEmailMessage();
   emailMsg.SetToAddresses(New String[] {userEmail});
   emailMsg.setSenderDisplayName(senderName);
   emailMsg.setSubject('Hello This is Mail From Salesforce After Batch Update');      
  
   } }
BDatlaBDatla
Hi Naveen,

I think you are miising the below code :


// Sends the email Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});

You need to invoke sendEmail() method .


Regards,
BDatla

 
BDatlaBDatla
Hi Naveen,

Let me know if you need any more help.

Regards,
BDatla
 
naveen kunurunaveen kunuru
 hey  hi 
i used the missing line 
i got an error: send email failed

   Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {emailMsg});