Newer Version Available

This content describes an older version of this product. View Latest

ConnectApi Utilities

The ConnectApi namespace contains a utility class.
Utility Description
ConnectApi.ConnectUtilities.unwrapApexWrapper() Unwraps obfuscated, Apex-wrapped objects into known types such as Map<String, Object>. Example from Apex Debug log: core.connect.apex.ApexMapWrapper@7270879d

Example

This example calls getManagedContentForSite(siteId, contentKeyOrId, showAbsoluteUrl) to get a custom content type with an image reference and uses the ConnectApi.ConnectUtilities.unwrapApexWrapper() utility.

1ConnectApi.ManagedContentDeliveryDocument res = 
2    ConnectApi.ManagedContentDelivery.getManagedContentForSite ('0DMXXXXXXXXXXXXXXX','MCLXXXXXXXXXXXXXXXXXXXXXXXXX',true);
3
4//before contentBody field ApexWrapper is unwrapped 
5system.debug(res.contentBody); 
6
7//unwrap contentBody field in res
8Map<String,Object> contentBody = (Map<String,Object>)ConnectApi.ConnectUtilities.unwrapApexWrapper(res.contentBody);
9
10//after contentBody field ApexWrapper is unwrapped, but image field still wrapped
11system.debug(contentBody);
12
13//before image field ApexWrapper is unwrapped 
14system.debug(contentBody.get('Image')); 
15
16//unwrap Image field in contentBody
17Map<String,Object> Image = (Map<String,Object>)ConnectApi.ConnectUtilities.unwrapApexWrapper(contentBody.get('Image'));
18
19//after image field ApexWrapper is unwrapped 
20system.debug(Image); 
21
22//replace wrapped primary_image in contentBody with unwrapped version
23contentBody.put('Image', Image);
24
25//after contentBody field ApexWrapper is unwrapped, with image field also unwrapped
26system.debug(contentBody);