My Apex controller returns a map<Account, list<String>>
map type to my Lightning JS controller. But when I access it in my component's JS controller, the map turns into an object!
This unwanted conversion creates a few issues:
Map methods like
mapName.keys()
don't work.The object isn't iterable, eg with
for(var [key, value] of myMap.entries()
In JS, unlike maps, objects can only have strings/symbols as keys. Which explains why my Apex map's sObject keys are now strings!
When I just retrieve a list of sObjects in my component controller, they are successfully stored as an object array, with the appropriate notation/syntax, ie:
{Id: "012345678912345", Name: "ABC Co"}
But in this former-map-turned-object, the sObject key has been stringified into something I can't use JSON.parse()
on, ie:
[Account (Id:012345678912345, Name:ABC Co)]
Which is strange because according to this doc,
Return results from a server-side controller to a client-side controller using the return statement. Results data must be serializable into JSON format.
What am I missing here?