I have an object called AssessmentForm
which has a lot of fields. Through an existing APEX controller I can access these specific fields by AssessmentForm.fieldname
.
Is there a way to convert all of the fields into a JSON?
For example:
Object: AssessmentForm
Which has the following fields: field1 = 5
, field2 = 'cat'
, field3 = 54
, field4 = 'dog
Would be converted to:
{"field1": 5, "field2" : "cat", "field3" : 54, "field4": "dog"}
For extra context, what I would like to do is send all of the form data through an API. To do so, I want to convert all of the fields in AssessmentForm
into a JSON. The form itself has a lot of fields on it and so I'm hoping there might be a way to convert an object's fields to a JSON without having to manually code it all out.