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
shiva1236shiva1236 

How to Automate Email So that every day at 10 AM the email should be delivered

Global class TmsEmailDemo 
{
public static void sendEmail() 
{
 Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
 
// Who you are sending the email to
   List<String> sendTo = new List<String>();
    sendTo.add('xyz@gmail.com');
    sendTo.add('abc@gmail.com');
	mail.setToAddresses(sendTo);
    System.debug(sendTo);

  mail.setTargetObjectId('0037F00000FWFGo');

   // The email template ID used for the email
   mail.setTemplateId('00X7F000000pTjc');
    				   
   //mail.setWhatId(candidate);    
   mail.setBccSender(false);
   mail.setUseSignature(false);
   mail.setReplyTo('cvb@gmail.com');
   mail.setSenderDisplayName('Ajay');
   mail.setSaveAsActivity(false);  
 
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

    }  
}
HI can anyone help me on how to Automate Email So that every day at 10 AM the email should be delivered.
Thanks in advance
 
Best Answer chosen by shiva1236
Aman MalikAman Malik
Hi,
To schedule your apex, you need to perform below steps:
  1. Implement the Schedulable interface in an Apex class that instantiates the class you want to run.
  2. From Setup, enter Apex Classes in the Quick Find box, select Apex Classes, and then click Schedule Apex.
  3. Specify the name of a class that you want to schedule.
  4. Specify how often the Apex class is to run.
    • For Weekly—specify one or more days of the week the job is to run (such as Monday and Wednesday).
    • For Monthly—specify either the date the job is to run or the day (such as the second Saturday of every month.)
  5. Specify the start and end dates for the Apex scheduled class. If you specify a single day, the job only runs once.
  6. Specify a preferred start time. The exact time the job starts depends on service availability.
  7. Click Save.
Below are some helpful links:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_scheduler.htm
https://salesforce.stackexchange.com/questions/137323/schedule-messaging-sendemail


Please mark the answer as best if this helps

Thanks,
Aman

All Answers

Aman MalikAman Malik
Hi,
To schedule your apex, you need to perform below steps:
  1. Implement the Schedulable interface in an Apex class that instantiates the class you want to run.
  2. From Setup, enter Apex Classes in the Quick Find box, select Apex Classes, and then click Schedule Apex.
  3. Specify the name of a class that you want to schedule.
  4. Specify how often the Apex class is to run.
    • For Weekly—specify one or more days of the week the job is to run (such as Monday and Wednesday).
    • For Monthly—specify either the date the job is to run or the day (such as the second Saturday of every month.)
  5. Specify the start and end dates for the Apex scheduled class. If you specify a single day, the job only runs once.
  6. Specify a preferred start time. The exact time the job starts depends on service availability.
  7. Click Save.
Below are some helpful links:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_scheduler.htm
https://salesforce.stackexchange.com/questions/137323/schedule-messaging-sendemail


Please mark the answer as best if this helps

Thanks,
Aman
This was selected as the best answer
shiva1236shiva1236
Hi Aman,
Thanks for the supoort...I followed your steps its working well.
But the problem is with my email template...It is only showing one name because of my email template.
Can you help me to give different name for different email id.
Below is my emale template snipp.User-added image
 
Aman MalikAman Malik
I did not understand your issue,
You are using {!Contact.Nam} in your template, even thouth you are getting same name for every contact?
Kindly put more light on this.
Thanks,
Aman