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
WesCooperWesCooper 

Date insert

I’m having an issue with inserting a date into a custom Date field. We are parsing through a file and extracting information. One of the pieces of information that is being extracted is a date value in the following format – mm-dd-yy.

 

I am currently setting this as a Date – Date dt = date.newinstance(y,m,d). But when I run this program to insert these values to a custom Date field, the program fails and I get the following error message - Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, mailing_date: invalid date

 

I used the Dev. Console to run this block of code to see what the date format is being set as:

 

Date dts = date.newinstance(12,4,24);

system.debug(dts);

 

The result is - 09:32:17:212 USER_DEBUG [2]|DEBUG|0012-04-24 00:00:00

 

My assumption was that since I am making this a Date and not a DateTime, that the time stamp would not be included. Also, the year is showing as 0012, rather then just “12” or “2012”. I thought that the Date type has a "format" method, but apparently it doesn't, only DateTime does.

 

I cannot figure out what I am doing wrong. Any help would be greatly appreciated.

 

Thank you once again,

 

Wes Cooper

DevAngelDevAngel

Here is a link to the documentation on creating a new instance of a Date object using year, month and day.

 

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_date.htm?SearchType=Stem&Highlight=Date|Dates|dates|date|DATE