DocSF

DocSF

Did You Know?

Docy turns out that context is a key part of learning.

How to deserialize a JSON String to Apex

String jsonText = '{"Data": {"attributes": {"type": "Contact","url":"/services/data/v35.0/sobjects/Contact/0036100000JUXKkAAP"},"Id": "0036100000JUXKkAAP","Description": "","LastName": "Testing"}}';

Map<String, Object> cObjMap = (Map<String, Object>) JSON.deserializeUntyped(jsonText);
String cObjJson = JSON.serialize(cObjMap.get('Data'));
// Why again :(
Map<String, Object> cObjMapFurious = (Map<String, Object>) JSON.deserializeUntyped(cObjJson);
String cObjJsonDrunk = JSON.serialize(cObjMapFurious);
try
{
    SObject customObject = (SObject)JSON.deserialize(cObjJsonDrunk, Sobject.class);
    System.debug(' Accomplished: '+customObject);
}
catch(Exception ex)
{
    System.debug(' @@@@@ Don't visible '+ex.getMessage());
}

Related Post

Salesforce speedtest

Come testare le prestazioni e la velocità di salesforc...

Salesforce Big Object

Trailhead Punti chiave dei Big Object An index mu...

Ricapitalizzazione sulle Banche Venete

Banca Popolare di Vicenza e Veneto Banca chiedono ad At...

Leave a Comment