2

I have setup Platform Cache on several dev orgs and each time I try to access a value I am getting null. I followed the steps from https://trailhead.salesforce.com/modules/platform_cache/units/platform_cache_use.

1)Setup the cache trial 2)Setup a New Platform Cache Partition called CurrencyCache

When I run the code provided on for org cache and session cached, the cachedRate is always null. Any idea why? I have tried this on three different orgs with the same result.

// Get partition
Cache.OrgPartition orgPart = Cache.Org.getPartition('local.CurrencyCache');

// Add cache value to the partition. Usually, the value is obtained from a 
// callout, but hardcoding it in this example for simplicity.
orgPart.put('DollarToEuroRate', '0.91');

// Retrieve cache value from the partition
String cachedRate = (String)orgPart.get('DollarToEuroRate');
system.debug(cachedRate);

// Get partition
Cache.SessionPartition sessionPart = Cache.Session.getPartition('local.CurrencyCache');

// Add cache value to the partition
sessionPart.put('FavoriteCurrency', 'JPY');

// Retrieve cache value from the partition
String cachedRate = (String)sessionPart.get('FavoriteCurrency');
system.debug(cachedRate);
2

I had to set Session and Org Cache allocation. Once I did, the code above worked.

Result

  • Great job! Mark your answer as accepted (you may have to wait a day) so others having the same problem can benefit f rom your experience – Sebastian Kessel Aug 9 '17 at 15:23
  • Its was really helpful for me ... – NITHESH K Aug 19 '17 at 5:15

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.