function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
anuragsinghnsanuragsinghns 

I would like to deserialize a parent record into the body of a child object

I would like to deserialize a parent into the child object I am not sure its possible but looking for advice.
Example:
opportunity opportunity =[select id,account.name from opportunity limit 1];
system.debug(json.serialize(opportunity));
this results in a string like this 
{"attributes":{"type":"Opportunity","url":"/services/data/v45.0/sobjects/Opportunity/0060D000002yQ5yQAE"},"Id":"0060D000002yQ5yQAE","AccountId":"0010D00000AdCKFQA3","RecordTypeId":"qwerty","Account":{"attributes":{"type":"Account","url":"/services/data/v45.0/sobjects/Account/0010D00000AdCKFQA3"},"Id":"00

 

when i try doing this 
opportunity opportunity =[select id,account.name from opportunity limit 1];
opportunity opportunity1 =(opportunity) json.deserialize(json.serialize(opportunity), opportunity.class) ;
system.debug('aa> '+opportunity1);

the opportunity fields are set but I see no account information in the debug.
 

Best Answer chosen by anuragsinghns
anuragsinghnsanuragsinghns

answerd my own question its a bit dumb on my side but if you do this system.debug('aa> '+opportunity1.account.name);

the value shows up just fine.