Is it possible to create a lightning event series in Apex?

It says that IsRecurrence2 and its related fields (Recurrence2PatternText, Recurrence2PatternVersion) are read only, but have to get set on initial event creation. When attempting to set them on a new event in Apex, it gives me Event.IsRecurrence2 is not writeable error.

Is it possible to set up an event series in Apex? Or does Salesforce only allow this from the front end?


Well it’s ugly but it SEEMS to work:

Event e = new Event();
Map<String, Object> untypedEvent = (Map<String, Object>) json.deserializeUntyped(json.serialize(e));
untypedEvent.put('IsRecurrence2', true);
// put other fields such as pattern
e = (Event) json.deserialize(json.serialize(untypedEvent), Event.class);
system.debug(e.IsRecurrence2); // shows true

Hopefully someone has a better answer though.

Here is an answer I wrote some time back about working with untyped objects and using JSON to serialize/deserialize them.

My instinct is that there is some sort of constructor or method that can be used to set the field that is being hidden from us and is not well documented.

Source : Link , Question Author : Tyler Dahle , Answer Author : gNerb

Leave a Comment