I am trying to upload the CSV file via Apex programming I am getting an error like Invalid Date Error. Please find the screenshot for more details. I have given code like this
site.Approved_Date__c =date.parse(inputsitevalues[13]);//date field [12].
Even though I have changed the date format as dd/mm/yyyy in CSV file I am getting the same error. Can anyone help me out in this issue.
Best Answer
It looks like the CSV file has the dates in mm/dd/yyyy format rather than dd/mm/yyyy. Hence the invalid date exception with the 31st month.
This will work:
This will fail with "System.TypeException: Invalid date: 5/31/2013"
From the Date.parse methods docs:
You can find the locale Date format information in the Supported Locales docs.
Another option would be to use the date format YYYY-mm-dd and date.valueOf().