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

I have 100 users in organization,i need to send greeting based on users date of birth , how can we do that?


I have 100 users in myorg.
 based on date of birth send greeting to particular users.

Please hlep me on this post.
Raj VakatiRaj Vakati
Hello , 

Can you please explain more on what you are trying to do? 
vikas rathi91vikas rathi91
Hello Mahesh,

You can do this through the Workflow rule.

Shruti SShruti S

Apex provides us 3 methods to send Emails - 

  • Workflow Email Alert
  • Process
  • Apex Trigger

To send Emails via these methods, we need some action to be done on the records (such a insert/update). But in our case, there is no action taking place on the records, hence Apex provides an other feature called Scheduled Apex which allows our Apex code to run everytime at a specific time.

Hence, for your usecase, you can write an Apex Class which would query all the User records and then iterate them and check if todays date is equal to the User's birth date, if yes, then send an Email or greeting. And once you have written the Apex Class, make this Apex Class to run everyday at a specific time using Scheduled Apex.

You can know more about Scheduled Apex here - (" target="_blank)

Mahesh K 22Mahesh K 22
Hi Shruti 
 I tried in same manner as you said ,but i am not able to send notification.
if you dont mind wrtite a logic and post it here.
Hi Mukesh,

There are several coupled approaches to achieve this. To help you I am providing to single approach using schedular. Please take help from this code and do necessary changes:
global class sendGreetingMsg implements Schedulable {
   global void execute(SchedulableContext SC) {
      //I trust your org have only 100 users
      //Customize logic based on date of birth
      List<User> users= [select id,Name,Email,DOB__c from user where DOB__c=today];

      // Step 0: Create a master list to hold the emails we'll send
      List<Messaging.SingleEmailMessage> mails = 
      new List<Messaging.SingleEmailMessage>();
      for (User myUser : users) {
        if (myUser.Email != null ) {
          // Step 1: Create a new Email
          Messaging.SingleEmailMessage mail = 
          new Messaging.SingleEmailMessage();
          // Step 2: Set list of people who should get the email
          List<String> sendTo = new List<String>();
          // Step 3: Set who the email is sent from
          mail.setSenderDisplayName('Sender Name');
          // (Optional) Set list of people who should be CC'ed
          List<String> ccTo = new List<String>();

          // Step 4. Set email contents - you can use variables!
          mail.setSubject('Greeting Message');
          String body = 'Dear ' + myUser.Name + ', ';
          body += 'Provide your greeting message here';
          // Step 5. Add your email to the master list
      // Step 6: Send all emails in the master list
Note: Do not forget to schedule this class.

Gulshan Raj
Mahesh K 22Mahesh K 22
HI GulshanRaj,
Thanx.Its working fine as we exepected.
Hi Mahesh,

If this resolve your problem, can you please mark this as solved , so that it gets removed from the unanswered queue which results in helping others who are encountering a similar issue.

Gulshan Raj