Sunday, July 12, 2020

Send email on daily basis in salesforce(With Schedulable Apex)

Problem :  How to send email on a daily basis to someone with salesforce.

Solution : First you have to write schedulable apex class.

                 Here is the code of simple code of schedulable class. Messaging is                    the namespace and SingleEmailMessage is the class. setSubject                    and setPlainTextBody are the methods of this class.

 


                 global class test1 Implements Schedulable
                      {
                           global static void execute(SchedulableContext sc)
                                {
                                     sendmail1();
                                 }
    
                          public static void sendmail1()
                               {
                                    string s='XYZ@gmail.com'; 
                                    Messaging.SingleEmailMessage email = new                                                                                                                                                 Messaging.SingleEmailMessage();
                                   string [] toaddress= New string[]{s};
                                    email.setSubject('Lovesalesforceyes');
                                   email.setPlainTextBody('salesforce blog');
                                    Messaging.sendEmail(New Messaging.SingleEmailMessage[]{email});
                                 }
                          }


            Then you have to set this schedulable apex on a daily basis . For this :


            1.) In setup write apex class.
            2.) Click on schedule apex as shown below :

                
apex class

             3.) Fill all the required fields.

              
schedule apex

    In apex class you have to give schedulable apex classselect start date, end     date and days according to your requirement and save it. That's all
 

   Thanks,
   Lovesalesforceyes.


    

                  

No comments:

Post a Comment

Get selected radio button value in LWC

This post explains how to get selected radio button in LWC. Below is demo of output : To use the radio button in LWC you have to use the  li...