I am working on a lwc. I am passing a array of json objects into a apex method. The parameter for the apex method is a List<Work_Items> where work items is a SF object. At run time apex converts the json to a list of work items but how to the sobjects field types convert. I have a flag field and need to check it. Will the json value for the field be converted to a bool on the sobject or will it be a string?
1 Answer
The types are all pretty much what you'd expect from JSON. Boolean values will be true/false (not String values). What follow is, I believe, what each type will be converted to, based on my experience. I haven't tested all of these, though, so a few may be incorrect; please feel free to let me know if any of these are wrong.
Apex Schema.DisplayType | JavaScript |
---|---|
address | Object of Fields e.g. { street: String, city: String, ... } |
any | String |
base64 | String |
Boolean | Boolean true or false |
Combobox | String |
Currency | Number |
DataCategoryGroupReference | String |
Date | String |
DateTime | String |
Double | Number |
String | |
EncryptedString | String |
ID | String |
Integer | Number |
Location | Object of fields { lat: Number, long: Number, ... } |
Long | Number |
MultiPicklist | String, semi-colon separated |
Percent | Number |
Phone | String |
Picklist | String |
Reference | Id or Object of fields e.g. { name: String, ... } |
String | String |
TextArea | String |
Time | String |
URL | String |
-
so true or false will in a json object will convert to a checkbox field as a bool– ZdevCommented Jan 27, 2023 at 20:05
-
-
2Worth noting the ISO formatting of date/time values, being in UTC. Weirdly the JSON and REST APIs handle some of this differently, IIRC.– Phil WCommented Jan 27, 2023 at 20:17