+ Start a Discussion
NishanNishan 

Help with inserting annual recurring event

Hi everyone,

                      I have to insert birthday events for a custom object called Mason__c. My code is not working. Can someone point out the mistake ? Thanks in advance

trigger BirthDayEvent on Mason__c (before update) 
{
	
    List<Event> eventList = new List<Event>();

	
	for(Mason__c mason :trigger.new)
	 {
	 	if(mason.Date_Of_Birth1__c != null)
	 	{     
	 		  decimal monthint =  mason.Date_Of_Birth1__c.month();
	 		  string monthstr;
	 		  if(monthint == 1)
	 		  monthstr = 'January';
	 		  else if(monthint == 2)
	 		  monthstr = 'February';
	 		  else if(monthint == 3)
	 		  monthstr = 'March';
	 		  else if(monthint == 4)
	 		  monthstr = 'April';
	 		  else if(monthint == 5)
	 		  monthstr = 'May';
	 		  else if(monthint == 6)
	 		  monthstr = 'June';
	 		  else if(monthint == 7)
	 		  monthstr = 'July';
	 		  else if(monthint == 8)
	 		  monthstr = 'August';
	 		  else if(monthint == 9)
	 		  monthstr = 'September';
	 		  else if(monthint == 10)
	 		  monthstr = 'October';
	 		  else if(monthint == 11)
	 		  monthstr = 'November';
	 		  else if(monthint == 12)
	 		  monthstr = 'December';
	 		  
	 		  
	 		  Event event = new Event();
	 		  date dt;
              dt=date.parse('01/1/2025');
              event.Subject ='Birthday ' + mason.Child_Name_1__c;
              event.startdatetime=mason.Date_Of_Birth1__c;
              event.enddatetime=mason.Date_Of_Birth1__c;
              event.OwnerId = UserInfo.getUserId();
              event.WhatId = mason.Id;
              event.ISRECURRENCE=true;
              event.RECURRENCETYPE='RecursYearly';
           	  event.RECURRENCESTARTDATETIME= mason.Date_Of_Birth1__c;
			  event.RECURRENCEENDDATEONLY=dt;
			  event.RecurrenceMonthOfYear = monthstr;
			  event.RecurrenceDayOfMonth = mason.Date_Of_Birth1__c.day();
              event.IsReminderSet = true;
              event.ReminderDateTime = DateTime.now().addDays(-2);
              eventList.add(event);
              
          }


        }


           if(eventList.size()>0)
           {
           insert eventList;
           }
           

}

 

digamber.prasaddigamber.prasad

Hi,

 

Looks like issue with setup of recurrency related fields. Please refer below to correct it:-

 

http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_event.htm

 

Let me know if you have any specific question.

 

Happy to help you!

NishanNishan

Hi,

       I have checked recurrence start, end, recurrence type, monthofyear and dayofmonth. Is anymore fields required with these? And my event is not getting inserted at all

digamber.prasaddigamber.prasad

Hi,

 

Have you checked debug log and see what error it is throwing? Please paste error message here.

NishanNishan

Hi,

     My trigger was deactivated. I realised that when I cj=hecked the log you suggested. So thank you. Just one doubt. In my code does the alarm occur every year ?

digamber.prasaddigamber.prasad

Hi,

 

Happy that your event records are getting created. I suspect that event records will be created as per your requirement. Could you please verify fields set by is according to http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_event.htm

 

Let me know if you have any specific question.

 

Happy to help you!