0

We have a custom object Yodlee_Accounts__c (Yodlee_Accounts__c) with a DateTime field (Yodlee_Last_Updated__c).

I am trying to create a new record with value set in the field as below without success. I am getting the following error.

enter image description here

   Yodlee_Accounts__c y = new Yodlee_Accounts__c();
    y.Yodlee_Last_Updated__c = DateTime.valueOf('2017-08-08T19:35:54Z');
    insert y;

Can someone tell me what I am doing wrong ?.

I believe the string already is in the Salesforce expected format.

2 Answers 2

1

Use DateTime.parse or DateTime.valueOf properly with the following formats

 y.Yodlee_Last_Updated__c = DateTime.parse('8/8/2017 12:00 AM');

or

 y.Yodlee_Last_Updated__c = DateTime.valueOf('2017-03-16 16:04:56');

or

y.Yodlee_Last_Updated__c = DateTime.valueOf('2007-01-02 05:17:00.000');
2
  • The parse method is locale dependent, so that format wouldn't work for everyone.
    – Adrian Larson
    Aug 15, 2017 at 16:52
  • actually, I have put all formatting in this answer, whatever suits OP can use this Aug 15, 2017 at 16:53
0

Date can create in the following way

 Datetime dt = DateTime.parse('10/14/2011 11:46 AM');

or

 Datetime GMTDate = Datetime.newInstanceGmt(2011,6,1,12,1,5);

or

Datetime myDate = Datetime.valueOf('2015-04-15 12:35:45');

Reference

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .