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(){
getPartition().remove(KEY_CALLER);
}
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
@AuraEnabled
public static String getTriageSessionInfo(){
return CallerSession.getAsJson();
}
Apex Controller - storing into Cache
@AuraEnabled
public static Account getCaller(String accountId){
if (accountId == null){
return null;
}
CallerSession.setCallerId(accountId);
return getAccount(accountId);
}
public static Account getAccount(String accountId){
return [SELECT Id,
FirstName,
LastName,
PersonBirthdate,
PersonEmail,
PersonHomePhone,
PersonMobilePhone,
PersonMailingStreet,
PersonMailingCity,
PersonMailingState,
PersonMailingPostalCode,
PersonMailingLatitude,
PersonMailingLongitude
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
?
The cache put calls are not allowed in a partition that the invoking class doesn’t own.
– Pranay Jaiswal Dec 14 '18 at 13:35the cache put calls are not allowed in a partition that the invoking class doesn’t own
actually mean? – Robs Dec 14 '18 at 15:26