As I began to mention in the comments of my previous post, I trying to store the Reports.ReportResults data into a custom caching object. I am able to store the data by converting the results to a String like so:

Reports.ReportResults results;
String stringResults = (String) JSON.serialize(results);

but when it comes to retrieving the results I seem to be in a bind. I thought I could accomplish this with something like this

String cache = [SELECT Results__c FROM Cache__c WHERE Report_Name__c = :report LIMIT 1].Results__c;
return (Reports.ReportResults) JSON.deserialize(cache, Reports.ReportResults.class);

But unfortunately that returns me with this fatal error:

FATAL_ERROR|System.JSONException: Apex Type unsupported in JSON: Object

Any ideas on if this is even possible or should I be working on a totally different approach? Any help would be greatly appreciated. Thank you.

  • 3
    Do you have access to Platform Cache? JSON does have some limitations, but I think the cache might work. – sfdcfox Dec 16 '15 at 22:09
  • Never heard of this. I see its caching layer is not available till Winter 16' is this still an option I can try right now? – Xtremefaith Dec 16 '15 at 22:11
  • Alternatively, JSON.deserializeUntyped? You won't get to convert it back directly into a Reports.ReportResults object, but at least you'd have a navigable map... – sfdcfox Dec 16 '15 at 22:13
  • I see it in my setup, but for some reason, we don't have any space allocated (0MB/0MB). It may be that we need to talk to our account executive, but I thought that Session and Platform cache were free, while other types (there's a half dozen or so) are paid cache. – sfdcfox Dec 16 '15 at 22:14
  • The platform cache documentation is definitely speaking my language but the deserializeUntyped seems like a quicker solution. How would that look? Never used it before – Xtremefaith Dec 16 '15 at 22:15

As suggested by @sfdcfox, I have the start of a solution using the newly released Platform Cache using the Org Cache approach described here

Reports.ReportResults results = Reports.ReportManager.runReport(reportId);
Cache.OrgPartition orgPart = Cache.Org.getPartition('local.PartionName');

// Retrieve cache value from the partition
if (orgPart.contains('ReportKey')) {
    Reports.ReportResults cachedResults = (Reports.ReportResults)orgPart.get('ReportKey');
// Add cache value to the partition
orgPart.put('ReportKey', results);

NOTE: ReportKey must be alphanumeric

The first time I ran this script I was happy to report that the results were stored as expected. Then, when I ran it the second time, after swaping the cast type from String to Reports.ReportResults the get() method worked as expected and I GOT MY RESULTS!

Kudos to sfdcfox for again being on point, and for opening my eyes to an option I didn't even realize was available.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.