2

After Summer 18 release on our Sandbox, we encountered couple issues, biggest being:

If i send custom class (with couple maps containing dates as keys) to aura, then stringify it and send it back as raw String to apex, then convert it to said class, I get

"FATAL_ERROR System.JSONException: Invalid format: "Tue May 01 00:00:00 GMT 2018" at [line:1, column:10928]"

Prior to Summer 18, this was not the case, so i'm pretty sure it's because of the new Release.

Any ideas on what to do with it? I'm not changing the date values in any way in Aura, just resending my custom class from aura to apex.

Here is the class code:

public class Warehouse_Report_Details {
    @AuraEnabled
    public Map<String, Account> accountsMap;
    @AuraEnabled
    public Account[] accounts;
    @AuraEnabled
    public Warehouse__c[] warehouses;
    @AuraEnabled
    public Map<String, Warehouse_hall__c[]> warehouseHallsByWarehouses;
    @AuraEnabled
    public Map<String, Hall_module__c[]> hallModulesByWarehouseHalls;
    @AuraEnabled
    public Map<String, Hall_module__c> modulesMap;
    @AuraEnabled
    public Module_line_item__c[] moduleLineItems;
    @AuraEnabled
    public Map<Date, Module_line_item__c> moduleLineItemsMap;
    @AuraEnabled
    public Map<Date, Module_line_item__c> moduleLineItemsMapAll { get; set; }
}

And here is aura JSON:

var data = JSON.stringify(component.get('v.warehouseDetails'));

After sending this value as "rawData" to apex and converting it to class:

Warehouse_Report_Details warehouseReportDetails = (Warehouse_Report_Details) JSON.deserialize(rawData, Warehouse_Report_Details.class);

i get said error.

Edit 1: Part of rawData String where it fails (same column as in error):

"moduleLineItemsMapAll":{"Tue May 01 00:00:00 GMT 2018":{"Hall_module__c":"a0M6E000000o1i6UAA","Date__c":"2018-05-01"

Edit 2: I found something very weird. When i log this in console from client-side. If the element is not open, it shows keys for map as this weird format, but if i expand it i get the right keys. Could this affect the string sent to apex somehow?

enter image description here

enter image description here

9
  • Can you post some relevant code that you have to be able to verify this?
    – Jayant Das
    Commented May 10, 2018 at 10:26
  • I added relevant code, but thing is this shouldn't produce errors, since it was tested just before summer 18 release and was working perfectly. As I said i'm not changing the values of dates in any way in aura.
    – LinQ
    Commented May 10, 2018 at 13:44
  • It seems as if after JSON.stringify dates are formatted to js format and apex is not able to read it? but that's weird since it could do it before.
    – LinQ
    Commented May 10, 2018 at 13:51
  • 1
    If there's have been no change and it's broken potentially because of the upgrade, have you tried reaching out to Salesforce support to get their opinion on this?
    – Jayant Das
    Commented May 10, 2018 at 14:03
  • 1
    This might be helpful, stackoverflow.com/questions/11491938/… ! Btw why do you need to stringify the response? Directly bind them into proper objects Commented May 23, 2018 at 12:49

1 Answer 1

1
JSON.stringify(new Date())

returns

"2013-10-06T15:32:18.605Z"

So when you try passsing it back to apex, its actually trying to convert DateTime into Date and hence you get "FATAL_ERROR System.JSONException: Invalid format: "Tue May 01 00:00:00 GMT 2018" at [line:1, column:10928]

Convert you map public Map<Date, Module_line_item__c> moduleLineItemsMap; to public Map<String, Module_line_item__c> moduleLineItemsMap;

Source: https://stackoverflow.com/a/19210578/4121395

2
  • Thanks for help, changing key type helped. I'm not serializing and deserializing date in js, i'm stringifying it only to pass object (custom class) attribute from aura to apex. I'm not sure if you are talking about serializing objects just for the sake of it, or doing it to pass it to apex, i've tried to pass attributes (with custom class type) to apex and i always had to stringify them or i would get "Internal Salesforce.com Error". Anyways thanks for help!
    – LinQ
    Commented May 23, 2018 at 13:23
  • Err my bad. :? Glad I was helpful. Commented May 23, 2018 at 13:24

You must log in to answer this question.

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