+ Start a Discussion

Birthday reminder

I am creating a workflowto assign a task for the contact owner before 7 days on contact's birthday.

I have created a formula field to calculate contacts next birthdate from Birthdate field using the following formula




IF(DAY(Birthdate) >=





I have assigned a task,now how do i test this?

Nirmal ChristopherNirmal Christopher

check the code in my next post it is 100% working

Nirmal ChristopherNirmal Christopher

global class memberBirthdayBatch implements Database.batchable<contact>
   global Iterable<contact> start(Database.batchableContext info)
       System.debug('Start method');
       return new callMemberIterable();     
   global void execute(Database.batchableContext info, List<contact> scope)
       List<contact> memsToUpdate = new List<contact>();
       System.debug('++++++++++++++++++++++Member list size is++++++++++++++++++++++++++ ' + scope.size());
       for(contact m : scope)
           Date myDate = date.today();
           Integer todayDy = myDate.day();
           Integer todayMon = myDate.month();
           Integer dy =  m.Birthdate.day();
           Integer mon =  m.Birthdate.month();
                      System.debug('++++++++++++++++++++++++++Day is ++++++++++++++++++++++++++' + m.Birthdate.day());

           if(todayDy == dy && todayMon == mon)
               Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
               List<String> toAddresses = new List<String>();
               List<String> ccAddresses = new List<String>();
               email.setSubject('Happy Birthday. Have a blast -- Birthday Reminder!');
               String message = '<html><table cellspacing = "7"><tr><td style="font-weight:bold;color:green;">Happy Birthday!!!</td></tr><tr><td style="font-weight:bold;color:pink;">Many more Happy returns of the day.</td></tr><tr><td></td></tr><tr><td></td></tr><tr><td style="font-weight:bold;">Cheers,</td></tr><tr><td style="font-weight:bold;">Magulan D</td></tr></table></html>';
               Messaging.sendEmail(new Messaging.SingleEmailMessage[]{email});
   global void finish(Database.batchableContext info)

Nirmal Christopher wrote:

      We cannot create birthday reminder using workflow because of the workflow conditions we give ...work  flow will fire only when the record is edited or inserted or when ever it is subsequently meeting the criteria.so user cannot update the record everytime inorder to fire it.

     You can also try creating time based workflow still it wont work for leap years. But there is a solution for this unless your org is not professional edition. You can try creating a apex scheduler class and create  scheduled job. The class will execute whenever time criteria meets. To test it you can run the anonymous code in developer console and check. I'l  post the code it will help you if u r working in Apex environment. check this code if the contact birthday is met todays date mail will trigger.its tested and 100% working.-----------------------


global class MemberIterable implements Iterator<contact>
   List<contact> memList{get; set;}
   Integer i {get; set;}

   public MemberIterable()
       memList = [SELECT EMail,Birthdate FROM contact];
       i = 0;

   global boolean hasNext()
       if(i >= memList.size())
           return false;
       } else {
           return true;

   global contact next()
       if(i > memList.size())
           return null;
       return memList[i-1];





global class callMemberIterable implements iterable<contact>
   global Iterator<contact> Iterator()
      return new memberIterable();
global class scheduleBirthdayWish implements Schedulable
    global void execute(SchedulableContext SC)
        memberBirthdayBatch mbw = new memberBirthdayBatch();

Ramakrishnan AyyanarRamakrishnan Ayyanar

1)If DOB is Feb 29 Leap year.How to find next birthday for that particular date?

No Need Validation rule for this code.

End-of-century years 1700, 1800,1900,2100 these years are not leap year in these problems are resolved.........

To find the next Birthday formula

How to create......

step-1: create the custom field for Date of Birth----It's type-Date

step-2: create the formula field for Birthday ---It's type-Date


iIF ( MONTH (ramki__DOB__c)=2 && DAY (ramki__DOB__c)=29,
OR(MOD(Year(Today())+ 4-MOD(Year(Today()),4),400)=0,
AND(MOD(Year(Today())+ 4-MOD(Year(Today()),4),4)=0,
MOD(Year(Today())+ 4-MOD(Year(Today()),4),100)<>0)),
Year(Today())+ 4-MOD(Year(Today()),4),
Year(Today())+ 8-MOD(Year(Today()),4))
IF (DATE (YEAR(TODAY()),MONTH(ramki__DOB__c),DAY(ramki__DOB__c)) > TODAY(),
DATE (YEAR(TODAY()),MONTH(ramki__DOB__c),DAY(ramki__DOB__c)),
DATE (YEAR(TODAY())+1,MONTH(ramki__DOB__c),DAY(ramki__DOB__c))

it's correctly worked for leap year dates.......
this is code for find the next Birthday friends......

Easily Calculate Age:

create formula field -------(Number)

Age=YEAR( ramki__BirthDay__c) - YEAR(ramki__DOB__c)