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
Maria AlexanderMaria Alexander 

hi all i'm fresher in salesforce and my qustions is get the email field value from object and send a email to the particular email id using a batch apex please help me to solvev

GauravGargGauravGarg
Hi Maria,

Please use SingleEmailMessage Object to throw email out of salesforce using apex. Please go through below article, this will let you know how to use this object:

http://salesforce.stackexchange.com/questions/1243/setting-a-from-address-in-singleemailmessage

Create one generic method in batch apex and pass email id through Parameters. 

Hope this helps you!!!

Thanks,
Gaurav
Anilkumar KotaAnilkumar Kota
Ramssf70Ramssf70
Hi Maria Alexander,

try bellow code
global      class emailbatchclass  implements Database.Batchable<sObject>
{
            
        global Database.QueryLocator start(Database.BatchableContext BC){
        {
        
        return database.querylocator('select id,name,email from contact  limit 5');
        
        }
        


        global void execute(database.BatchableContext bc , List<sobject> conlist)
        {
        string body;
       List<Messaging.SingleEmailMessage> mails =   new List<Messaging.SingleEmailMessage>();
       List<String> sendTo = new List<String>(); 
                        
                for(contact mycontact :conlist)
                {
                
                Messaging.SingleEmailMessage mail =  new Messaging.SingleEmailMessage();
                   sendTo.add(myContact.Email);
                mail.setToAddresses(sendTo);
                mail.setSubject('URGENT BUSINESS PROPOSAL');
                body = 'Mymail body';
                mail.sethtmlBody(body);
                
                mails.add(mail);
                }
                Messaging.sendEmail(mails);
          }
          
          global void finish(database.batchblecontext bc)
          {
              
              
              
          }
  
  
}















}


Thank you
 
Maria AlexanderMaria Alexander
here what write into  the developer console to send a email Please Help me 

global      class emailbatchclass  implements Database.Batchable<sObject>

{

             

        global Database.QueryLocator start(Database.BatchableContext BC){

        {

         

        return database.querylocator('select id,name,email from contact  limit 5');

         

        }


        global void execute(database.BatchableContext bc , List<sobject> conlist)

        {

        string body;

       List<Messaging.SingleEmailMessage> mails =   new List<Messaging.SingleEmailMessage>();

       List<String> sendTo = new List<String>();

                         

                for(contact mycontact :conlist)

                {

                 

                Messaging.SingleEmailMessage mail =  new Messaging.SingleEmailMessage();

                   sendTo.add(myContact.Email);

                mail.setToAddresses(sendTo);

                mail.setSubject('URGENT BUSINESS PROPOSAL');

                body = 'Mymail body';

                mail.sethtmlBody(body);

                 

                mails.add(mail);

                }

                Messaging.sendEmail(mails);

          }
          global void finish(database.batchblecontext bc)

          {

          }
}


}

in Developer console what function to write to send  an email Please help me 
Ramssf70Ramssf70
HI Maria Alexander,
emailbatchclass  obj = new emailbatchclass();
database.executeBatch(obj);


Thankyou