0

Can anyone provide me sample apex code to create recurring event in salesforce.

I am using below code:

Event newEvent = new Event();
newEvent.OwnerId = '023170000004yO9AAI';
newEvent.Subject ='Test';
newEvent.WhatId = recordId;
newEvent.IsRecurrence = true;
newEvent.RecurrenceStartDateTime = System.today();
newEvent.RecurrenceEndDateOnly = System.today()+30;
newEvent.RecurrenceType = 'RecursDaily';
newEvent.IsAllDayEvent =true;
newEvent.DurationInMinutes =1440;
newEvent.ActivityDate = yagyaPerformanceObj.Start_Date__c;
insert newEvent;

I am using above code to create recurring event. My requirement is to create recurring event for 30 days which recurs daily. I am getting this error 'REQUIRED_FIELD_MISSING, Required fields are missing: [Recurrence Interval]: [Recurrence Interval]'

I don't know which field I am missing.

5
  • Is there a problem you are running into specifically we can help with? Have you tried anything yet?
    – Kyle
    Commented Oct 8, 2014 at 20:08
  • Let's see what you have so far.
    – Jan J
    Commented Oct 8, 2014 at 20:27
  • Ankush, can you elaborate on what you require - the circumstances and what you have attempted thus far?
    – Cerbera
    Commented Oct 8, 2014 at 20:34
  • @Kyle I have modified my question. Can you please provide your input now. Commented Oct 9, 2014 at 14:30
  • It's worth noting that the error message told you which field you were missing: Recurrence Interval (RecurrenceInterval). It's pretty annoying that it appears to be giving you the label name instead of the API name, but you can always find the API name by going into the Object Manager. Commented Jan 30, 2018 at 7:23

2 Answers 2

6

See the salesforce documentation on the Event object.

It looks like you are trying to do a 'RecursDaily' type of event. According to the documentation above (and in particular the table located at the bottom of the page), that means you should also be populating the RecurrenceInterval field.

So your code would be:

Event newEvent = new Event();
newEvent.OwnerId = '023170000004yO9AAI';
newEvent.Subject ='Test';
newEvent.WhatId = recordId;
newEvent.IsRecurrence = true;
newEvent.RecurrenceStartDateTime = System.today();
newEvent.RecurrenceEndDateOnly = System.today()+30;
newEvent.RecurrenceType = 'RecursDaily';
newEvent.RecurrenceInterval = 1; // This means that the event will wait 1 day before recurring again
newEvent.IsAllDayEvent =true;
newEvent.DurationInMinutes =1440;
newEvent.ActivityDate = yagyaPerformanceObj.Start_Date__c;
insert newEvent;
1
  • Salesforce doc. link doesn't appear to be working Commented Dec 9, 2014 at 18:25
0

Not sure what your expecting .. Edit your question?

trigger ClassTrigger on Class__c (after insert) {
Map<String, Class__c> clasMap = new Map<String, Class__c>();
// after Classes are inserted
   List<Event> followupEvents = new List<Event>();// build list in memory
   for (Class__c clas : System.Trigger.new) {
    date t = clas.Start_Date__c;
          datetime xStartDate = DateTime.newInstance(t.year(),t.month(),t.day());
   Event event = new Event(
    ActivityDate = clas.Start_Date__c ,
    RecurrenceEndDateOnly = clas.End_Date__c ,
    RecurrenceStartDateTime = xStartDate,
    RecurrenceType = 'RecursEveryWeekday',
    RecurrenceDayofWeekMask = 1,
    IsRecurrence = TRUE,
    Description = 'Class Event.', 
    Event_Type__c = 'Customer Training',
    Call_Objective__c = 'training',
    Location = clas.Facility__c , 
    IsAllDayEvent = TRUE, 
    Event_Status__c = 'Not Started', 
    Subject = 'Class trigger Event');
  followupEvents.add(event);  // add to list
   }

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .