System.TypeException: Invalid date: 1/1/2014 error issue
whenever we are assaigning a string which contains date to date field ,we get this error because of different date format.So to resolve this issue we need to change date format.
For example I got this error "System.TypeException: Invalid date: 1/1/2014"
I resolved this issue in the following way..
string DateScheduled='1/1/2014';
String[] myDateOnly = DateScheduled.split(' ');
String[] strDate = myDateOnly[0].split('/');
Integer myIntDate = integer.valueOf(strDate[1]);
Integer myIntMonth = integer.valueOf(strDate[0]);
Integer myIntYear = integer.valueOf(strDate[2]);
account.DateScheduled__c=Date.newInstance(myIntYear, myIntMonth, myIntDate);
Here DateScheduled__c is a custom date field in account object.
Hope this helps you...
whenever we are assaigning a string which contains date to date field ,we get this error because of different date format.So to resolve this issue we need to change date format.
For example I got this error "System.TypeException: Invalid date: 1/1/2014"
I resolved this issue in the following way..
string DateScheduled='1/1/2014';
String[] myDateOnly = DateScheduled.split(' ');
String[] strDate = myDateOnly[0].split('/');
Integer myIntDate = integer.valueOf(strDate[1]);
Integer myIntMonth = integer.valueOf(strDate[0]);
Integer myIntYear = integer.valueOf(strDate[2]);
account.DateScheduled__c=Date.newInstance(myIntYear, myIntMonth, myIntDate);
Here DateScheduled__c is a custom date field in account object.
Hope this helps you...
No comments:
Post a Comment