function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
EchoEchoEchoEcho 

Creating a Task from Apex

I'm trying to create a Task from Apex for the current logged in user. It seems simple enough, and I'm doing pretty much exactly what is specified in the Developer Guide:

 

                 //create a task for the user
                //Task newTask = new Task(Subject='Complete Survey for Transaction');
                Task newTask = new Task(Description = 'Survey Transaction',
                                        Priority = 'Normal',
                                        Status = 'Inbound Email',
                                        Subject = 'Other',
                                        IsReminderSet = true,
                                        ReminderDateTime = System.now()+1,
                                        WhoId = userContact[0].ContactId    );             
                insert newTask;

 

But I keep getting this exception:

 

Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Free-form text is not allowed for the Subject field. Please select a pre-determined value from the picklist.: [Subject]

 

The subject that I've specified ('Other') is in the Task subject picklist, and Task.Subject is supposed to be a String, so I don't know what else I'm supposed to do to get it to match up my subject with the pre-determined values...

 

Anybody happen to know?

 

Thanks,

Tom 

Best Answer chosen by Admin (Salesforce Developers) 
aalbertaalbert

Do you have any custom validation rules on the Task object (Setup -> Customize -> Activities -> Task Validation Rules)?

 

All Answers

aalbertaalbert

Do you have any custom validation rules on the Task object (Setup -> Customize -> Activities -> Task Validation Rules)?

 

This was selected as the best answer
EchoEchoEchoEcho
Doh! It would appear that I do. Thanks ;-)