1

Currently, I've used the postman to make a request to standard Saleforce API. At the Date field I inputted year only. enter image description here
As I expected, that should be inserted fail for that case. But actually, the record inserted successful. And I've taken a look at the date field, it populated the first day of inputted year.

enter image description here
That's so strange. As I known that salesforce API allow only the input date with format: yyyy-MM-dd. I tried to research why but no luck. Could anyone give me an explanation or related document about this?? Thanks in advance!

1 Answer 1

1

Edit: As I suspected, the JSON parser used by the REST API allows extra formats that are not documented in the documentation. It is strongly recommended that you use only the documented date format specification (YYYY-MM-DD).


The SOAP API specifically requires (YYYY-MM-DD) for date fields. For the REST API, you can use (almost?) any ISO 8601 format, including such options as:

Format Example Note
YYYY 2022 Assumes Jan 1st (1/1/2022)
YYYY-MM 2022-07 Assumes first day of month (7/1/2022)
YYYY-MM-DD 2022-07-09 n/a
YYYY-Www 2022-W27 Returns Monday of that week (7/4/2022)
YYYY-Www-D 2022-W27-6 1=Monday, 7=Sunday (7/9/2022)
YYYY-DDD 2022-190 1=Jan 1, 365=Dec 31 in non-leap year (7/9/2022)

I'm not entirely sure where this is called out in the documentation, however. Just be aware that you can use a variety of date formats with the REST API.

6
  • Thanks @sfdcfox for the quick rep. That's make me a little bit confused. The document below point me for the require format: yyyy-MM-dd format developer.salesforce.com/docs/atlas.en-us.api_rest.meta/…
    – Dung Rieu
    Jul 10, 2022 at 6:37
  • @DungRieu I don't know if it's documented, but I'll ask.
    – sfdcfox
    Jul 10, 2022 at 14:35
  • @DungRieu By the way, it's an undocumented feature and should not be relied on.
    – sfdcfox
    Jul 10, 2022 at 19:26
  • thanks for your great support. I've tested your table, and that's really worked as you said. But If that hasn't any official information or undocument feature. So should I think the current issue is a Salesforce's bug?
    – Dung Rieu
    Jul 11, 2022 at 0:51
  • @DungRieu It's not a bug, it's an undocumented feature. For example, there is a special Apex namespace called Apex. It's not documented, and it only has a few classes in it. One such class in there is Apex.Stack, which is a First-In, Last-Out buffer implementation. I found it by accident once, and was similarly told not to use it, because it's not production quality, whatever the limits were. So, there are things that are in the system that are simply left undocumented on purpose. They're not bugs.
    – sfdcfox
    Jul 11, 2022 at 2:55

You must log in to answer this question.

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