Ok so I've been trying to sort this out all day and I've not made a single bit of progress.
I have a set up a site on Salesforce as a web service endpoint. A client's system sends an HTTP request with a few bits of information as GET parameters and then our salesforce updates a record.
I noticed that the date was saving an hour later than it was and I cannot get it to save correctly no matter what I have tried.
The Custom_Object__c has two datetime fields, one which is set to Datetime.now() when the record is created, we'll call that Datetime_1__c. This one saves correctly. The other field, Datetime_2__c is set when the HTTP request comes through with a date string in the GET parameters. The date string is +01:00 time zone, and requires a bit of reformatting before converting.
The apex code is below:
String dtStr = g_datetime.substring(0, 19).replaceAll('T', ' ') + '+01:00';
System.debug('Date/Time string to save:' + dtStr);
Datetime dt = Datetime.valueOf(dtStr);
System.debug('Date/Time to save:' + String.valueOf(dt));
relatedRecord.Receipt_Received_At__c = dt;
The debug log shows these two entries:
13:58:07.038 (38233077)|USER_DEBUG|[49]|DEBUG|Date/Time string to save:2014-06-19 14:44:00+01:00
13:58:07.038 (38416001)|USER_DEBUG|[51]|DEBUG|Date/Time to save:2014-06-19 14:44:00
But when I go on the record detail page, the time shows as 15:44. My user time zone is BST (+01:00) and so is the company default, but when I set these to any other time zones it STILL puts the date an hour ahead.
What do I need to add or remove from my code to make this appear correctly?