Our requirement is to create a set of recurring tasks(activities) programatically. It's supposed to be a simple recurring set of tasks up to X number of days.

My code segment as below.

Integer idx = 0;
List<Task> list_tsk = new List<Task>();
Datetime nextdt = Datetime.now();
while(idx < 10){

    nextdt = nextdt.addDays(idx);

    Task tsk = new Task();
    Tsk.Subject = 'Recurring:';
    tsk.ReminderDateTime = nextdt.addHours(-1);
    tsk.ActivityDate = nextdt.date();
    //tsk.Status = 'Not Started';
    tsk.OwnerId = UserInfo.getUserId();
    tsk.RecurrenceInterval = 1;
    tsk.RecurrenceRegeneratedType = 'After due date';
    //tsk.RecurrenceType = 'Daily';


    insert list_tsk;
Catch(Exception ex)
    System.debug('exep: '+ex.getLineNumber() +' - '+ex.getMessage());

But insertion is failing with error:

Insert failed. First exception on row 0; first error: INVALID_OR_NULL_FOR_RESTRICTED_PICKLIST, Repeat This Task: bad value for restricted picklist field: After due date: [RecurrenceRegeneratedType]

Is it not possible to create a recurring series of tasks? Or am I doing it wrong? Is there any working example of programatic task creation which I could refer to please? Appreciate any help on this. Thanks.


1 Answer 1


You're not populating some of the required fields or not populating them correctly. Take a look at the Object Reference for Tasks. Here's some of what's relevent:





Create, Defaulted on create, Filter, Group, Sort


Indicates whether the task is scheduled to repeat itself (true) or only occurs once (false). This is a read-only field on update, but not on create. If this field value is true, then RecurrenceStartDateOnly, RecurrenceEndDateOnly, RecurrenceType, and any recurrence fields associated with the given recurrence type must be populated. See Recurring Tasks.

You must log in to answer this question.

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