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.

  • Is there a problem you are running into specifically we can help with? Have you tried anything yet? – Kyle Oct 8 '14 at 20:08
  • Let's see what you have so far. – Jan Julian Oct 8 '14 at 20:27
  • Ankush, can you elaborate on what you require - the circumstances and what you have attempted thus far? – Cerbera Oct 8 '14 at 20:34
  • @Kyle I have modified my question. Can you please provide your input now. – Ankush Dureja Oct 9 '14 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. – Nathan Hinchey Jan 30 '18 at 7:23
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;
  • Salesforce doc. link doesn't appear to be working – Brad Thomas Dec 9 '14 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
   }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.