You need to sign in to do that
Don't have an account?
Java SOAP API Date problem
Hi guys,
I have a very strange problem with a custom DateTime field. When I write any date+time value, the date will write correctly but the time portion will always be written at 01:00:00 For example the java Date object contains 2013-09-24T15:53:27.000Z (as confirmed by a trace output statement) then when the field is written to Salesforce it will display as "24/09/2013 01:00". Fields are being written in the usual way:
javaDate=new Date();
SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" );
String strFormattedDate = sdf.format(javaDate);
System.out.println("javaDate="+strFormattedDate);
SObject[] records=new SObject[0];
records[0].setType("CustomTable__c");
records[0].setField("DateCreated__c", javaDate);
saveResults = conn.create(records);
Any idea why this is happening? Is it something about my custom Date/Time field "DateCreated__c" ???
Thanks,
Mark.
IIRC, in WSC (which it looks like you're using, but you don't say), Date is used for date only values and Calendar is used for date/time values. (so set your field value to Calendar.newInstance() instead of new Date() and see how that works)
All Answers
IIRC, in WSC (which it looks like you're using, but you don't say), Date is used for date only values and Calendar is used for date/time values. (so set your field value to Calendar.newInstance() instead of new Date() and see how that works)
Thanks that was the problem :)
Now another problem. When I pass the Calendar object it seems to ignore the timezone component
Our Salesforce timezone is set to GDT (GMT+1)
I pass a Calendar object with the time set to "2013-09-24 15:53:27" and the timezone set to "GMT"
The time written to Salesforce is "2013-09-24 14:53:27", which is then displayed in the UI as "24/09/2013 15:53"
This is the same regardless of what timezone I set in the Calendar object. The time will always be written as "2013-09-24 14:53:27"
What I think is happening is that the Calendar timezone component is being ignored, Salesforce interprets the time as "15:53:27 GDT" and converts it to "14:53:27 GMT" before storing it.
Is there any way I can force the SOAP API to write the date/time as I specify it and not make any adjustments???
Thanks
You should use Java Calender class for SFDC Datetime.
Thanks.