You need to sign in to do that
Don't have an account?
Mathías del Valle Sanchez
How to serialize an object as JSON?
Hi,
I got a problem, i need to convert the "Case" Object into a Json and after convert that Json in a Object
I know that i have to use JSON.serialize and JSON.deserialize. but i don't how.
I got a problem, i need to convert the "Case" Object into a Json and after convert that Json in a Object
I know that i have to use JSON.serialize and JSON.deserialize. but i don't how.
The example provided in https://www.infallibletechie.com/2017/09/how-to-convert-sobject-to-json-string.html is in the context of Contact object but should help you get started.
Also see https://salesforce.stackexchange.com/questions/101885/parse-json-string-to-object
If this information helps, please mark the answer as best. Thank you
Try The Below Code Please Mark it As Best Answer If it Helps
Thank You!
Hi Mathías ,
If you have to convert object into JSON format then you need to use JSON.serialize.
Case c1= new Case();
c1.Subject = 'case subject';
String jsonStr = JSON.serialize(c1);
And if have to have to convert JSON format into Object then you need to use JSON.deserialize.
Case c2 = (Case) JSON.deserialize(jsonStr , Case.class);
Please Mark it as Best Answer, if it helps!
Thanks