I am using the Platform Cache to store the Id of the customer the salesperson is speaking with on the phone, such that different Lightning Components automatically load the customer's details as the salesperson navigates around Salesforce Lightning.

Example Apex code

public class CallerSession {

private static final String PARTITION_NAME = 'local.xxxx';
private static final String KEY_CALLER = 'CallerId';

public static Id getCallerId(){

    if (getPartition().contains(KEY_CALLER)){
        return (Id)getPartition().get(KEY_CALLER);    
    return null;

public static void setCallerId(Id callerId){
    if (callerId != null){
        getPartition().put(KEY_CALLER, callerId);    

public static void clearCache(){

private static Cache.SessionPartition getPartition(){
    return Cache.Session.getPartition(PARTITION_NAME);

public static String getAsJson() {

    Map<String, String> ids = new Map<String, String>();
    ids.put('callerId', getCallerId());
    return JSON.serialize(ids, true);

Apex Controller - getting from cache

public static String getTriageSessionInfo(){
    return CallerSession.getAsJson();

Apex Controller - storing into Cache

public static Account getCaller(String accountId){

    if (accountId == null){
        return null;


    return getAccount(accountId);

public static Account getAccount(String accountId){

    return [SELECT Id, 
            FROM Account 
            WHERE IsPersonAccount = true 
            AND Id =:accountId];

One Lightning Component stores into the Cache, all other components get from the cache.

I recently set up a Sales Console app, but the Lightning Component do not Save\Load the Id from the Platform Cache

I cannot find any documentation explaining this behaviour.

Is Platform Cache compatible with Sales Console?

  • It should be , Can you provide relevant code? Commented Dec 14, 2018 at 13:23
  • @PranayJaiswal code added
    – Robs
    Commented Dec 14, 2018 at 13:26
  • 1
    how are you putting Id in cache? Is it the same class that Aura Apex controller is? I can see from documentation The cache put calls are not allowed in a partition that the invoking class doesn’t own. Commented Dec 14, 2018 at 13:35
  • @PranayJaiswal updated with more code and further explanation
    – Robs
    Commented Dec 14, 2018 at 13:55
  • @PranayJaiswal what does the cache put calls are not allowed in a partition that the invoking class doesn’t own actually mean?
    – Robs
    Commented Dec 14, 2018 at 15:26

1 Answer 1


I suspect this may be related to using the Session Cache rather than the Org Cache. The session cache is tied to the individual user sessions.

When a user is signed in the actually have a few different active sessions that depend on how they are using Salesforce. See User Session Types and Different Session Ids in Different contexts.

Another possibility is that the data isn't being persisted in the cache until it is requested. This might happen if there is no storage space allocated to the partition or if additional data being added to the partition caused it to be dropped.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .