0

I am inserting one record to Custom_object__c that object contains the DateTime field,here am a russian user to insert.If i use a date format as "Startdate:22.02.2014"(JSON request) means its accept, if i use date format as "Startdate:22/02/2014"(JSON request) its not accept it shows Invalid date:22/02/2014 date error. My salesforce admin is a UK user.How to resolve this using Datetime methods i try it through datetime methods but it throwing a error as Invalid date..

Input format as

"ArraySample":[
    {
      "ID" : "107081070810708",
      "samplevalue" : "apple",
      "StartDate" : "20/2/2014",
      "StartTime" :"10:02:00"

    }
]
  • This format is working for United Kingdom(UK "StartDate" :"20/2/2014") Russian Country date format is dd.mm.yyyy but am giving StartDate as 20/2/2014 its throwing a error as Invalid date:20/2/2014.

How can resolve this issue using apex class?

  • Can't you just use format() in apex method that you call? – Artur Kępczyński Feb 20 '14 at 8:17
2

I am assuming the JSON is received or sent between different systems. So why not use the ISO date format http://www.w3.org/TR/NOTE-datetime ?

And then in apex

DateTime dt = (datetime)json.deserialize('"2014-06-20T20:55:00.000Z"', datetime.class);
0

To really help on a design level, we'd need to know more about your process and where the json is coming from that different date formats can be present in it. As basicly, you'd like to normalize data entry before processing it. Guide users to insert date in a same format by validating their input or giving them a graphical utility for instance.

If that can not be done, i think your only strategy is to build an apex parser that will try to parse each possible format with the default possibilities or by breaking the string apart and making a new DateTime record using the various newInstance() methods.

DateTime methods

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.