1

We have created a form in our website to submit info that will create a Lead in Salesforce. Two of the Custom Fields we have are a Departure Date and Return Date. We are submitting the date in the correct ISO 8601 format of yyyy-MM-dd and the API request is correct and the response back is successful. However, the values in the Lead in Salesforce when our team views it is that the date is a day earlier.

Example: 2017-09-15 submitted in the JSON request is showing up in the Salesforce Lead as 9/14/2017.

JSON String:

{
    "Agent_IATA__c": "00000000",
    "Agency_Name__c": "DEMO AGENCY",
    "FirstName": "TEST",
    "LastName": "TEST",
    "phone": "555-111-3311",
    "Email": "test@test.com",
    "Best_Time_To_Call__c": "Morning",
    "Time_Zone__c": "Pacific Time",
    "Lead_Passenger_Name__c": "DEMO TEST",
    "Number_Of_Adults__c": "4",
    "Number_Of_Children__c": "1",
    "Departure_Date__c": "2017-06-24",
    "Departure_City__c": "Philadelphia",
    "City1__c": "London",
    "City2__c": "Dublin",
    "City3__c": "",
    "City4__c": "",
    "City5__c": "",
    "Number_Of_Nights1__c": "4",
    "Number_Of_Nights2__c": "4",
    "Number_Of_Nights3__c": "",
    "Number_Of_Nights4__c": "",
    "Number_Of_Nights5__c": "",
    "Return_Date__c": "2017-07-05",
    "Return_From__c": "Dublin",
    "Hotel_Star_Rating__c": "4 Star",
    "Estimated_Total_Budget__c": "18000",
    "Feedback_Comments__c": "TEST",
    "Air_Needed__c": "Yes",
    "Class_of_Service__c": "Coach",
    "Travel_Between_Cities__c": "Car",
    "BussinessType__c": "FIT",
    "ImmediateBussiness__c": false,
    "RecordTypeId": "000000000000",
    "Web_Routing_Id__c": "Quote Request",
    "RefferingAgent__c": ""
}

We've also tried submitting the JSON request via and external app called POSTMAN and it also has the wrong date in Salesforce.

Does anyone have any idea what could be the problem?

  • did u check your salesforce instance Default time zone in set up > company information ? – sf_user Jan 20 '17 at 18:42
  • 1
    Are Departure Date and Return Date for sure of the type Date? If they were Datetime you might get some time zone issues. – Adrian Larson Jan 20 '17 at 18:44
  • 1
    Can you please post the JSON string being sent, the TimeZone of the REST API user, and the TimeZone of the Org. This is most likely a timezone issue and the JSON string probably includes a time component – Eric Jan 20 '17 at 18:51
  • 1
    "Don't worry about the world coming to an end today. It's already tomorrow in Australia." --Charles M. Schulz ... If your integration user is GMT-0:00 or further East, then the dates are correct from a global perspective. Try setting your integration user to a Western time zone. – sfdcfox Jan 20 '17 at 18:57
  • Our Default Time Zone is Pacific Standard Time, which is correct. Both Dates are set up as Date/Time. I believe, however, that we want it this way. I'll have to check with our managers to see if maybe we could change it to just Date. Integration User is also the same timezone as well. I will include the JSON as well! – Michelle M Jan 20 '17 at 20:15
1

In our REST based services we have always passed the date values in the following format.

"CommittedDate": "01/22/2017", "RequestedDate": "02/02/2016"

In the REST service we use the Date.Parse method to parse the date.

Date dt = Date.Parse(CommittedDate);

This seems to work with salesforce REST service.

Edit:

So I tried some code to use a time component. This seems to work in execute anonymous.

string td = '01/01/2017 11:46 AM';
DateTime dt = DateTime.Parse(td);
System.Debug(dt);
  • Hello, our custom field is set up as a Date/Time, not Date, so just submitting "09/15/2017" is throwing a JSON error: { "message": "Cannot deserialize instance of datetime from VALUE_STRING value 09/09/2017 or request may be missing a required field at [line:1, column:392]", "errorCode": "JSON_PARSER_ERROR" } – Michelle M Jan 23 '17 at 21:21
  • @MichelleM Did you try the second part where I have passed the datetime string? – abhi Jan 24 '17 at 16:19
  • I did add the time to the formatted string yyyy-MM-dd and it successfully submitted correctly. I used the local time of 5:00 AM and that submitted the correct date. – Michelle M Jan 25 '17 at 17:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.