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
augiewazaugiewaz 

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

aalbertaalbert

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. 

 

augiewazaugiewaz

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

aalbertaalbert

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.