You need to sign in to do that
Don't have an account?

FIELD_CUSTOM_VALIDATION_EXCEPTION in Test Method
Hi,
I am trying to create a test method for a trigger/apex class I have created on Event records
In the test method, when I have an Event that is an All Day Event, I am getting a FIELD_CUSTOM_VALIDATION_EXCEPTION error when trying to set the StartDateTime and EndDateTime.
The exact error message is:
System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, startTime: 2009-02-09 00:00:00
Here is a snippet of the code where the issue lies:
Event e = new Event(RecordTypeId=eventRecType.Id, Type='Other'); Date today = Date.today(); e.OwnerId = nonSrcMngUsers[0].Id; e.IsAllDayEvent = true; e.StartDateTime = DateTime.now(); e.EndDateTime = DateTime.now();
I have also tried things like this but without any luck:
e.StartDateTime = DateTime.valueOf(today + ' 00:00:00'); e.EndDateTime = DateTime.valueOf(today+1 + ' 00:00:00'); e.StartDateTime = DateTime.valueOf(today + ' 00:00:00'); e.EndDateTime = DateTime.valueOf(today + ' 23:59:59');
I actually do need to have values in these fields as I am testing them in my apex class and they cannot have a null value.
Any suggestions????
Thanks in advance
Warren
Do you have any Validation Rules on the Event objects (check by going to Setup->App Setup->Customize->Activities->Event Validation Rules)? A validation rule might be preventing it from being created.
Thanks for the response.
No, there is no validation rule on the Event object. I have the feeling it is something in the background from Salesforce.com when creating events that are marked as All Day Events
Check out this link from the API docs. It details out the specific Event fields that can be set when setting an all day event and more related details.