-
-
Save Xtremefaith/46735947b0df20db53d4 to your computer and use it in GitHub Desktop.
VF Component PageReference fails to use Platform Cache put() method, throwing a Cache.PlatformCacheInvalidOperationException
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Dashboard{ | |
/* Constructor */ | |
public void init() { | |
this.accountWrapper = getAccount(); | |
} | |
public PageReference pageRefreshData(){ | |
/*============= THIS ATTEMPT SUCCEEDS ==================*/ | |
try{ | |
Cache.OrgPartition customPartition = Cache.Org.getPartition('local.CustomData'); | |
customPartition.put('test', 'pageRefreshData()'); | |
}catch(Exception e){ System.debug('::CACHING ERROR:: '); } | |
return null; | |
} | |
//========= WRAPPER/CONTAINER CLASSES ============// | |
/* wrapper/container class */ | |
public class AccountWrapper{ | |
public String id { get; set; } | |
public String name { get; set; } | |
public Boolean isGroup { get; set; } | |
public AccountWrapper(Account a){ | |
this.id = a.Id; | |
this.name = a.Name; | |
this.isGroup = (a.Name.contains('Group')) ? TRUE : FALSE; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<apex:page sidebar="false" controller="FranchiseDashboard" action="{!init}"> | |
<c:Widget data-controller="{!dashboard}" widget-type="metric" widget-title="Title of widget" ... /> | |
</apex:page> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class metricController extends Widget { | |
//========= SETUP GETTERS/SETTERS ============// | |
/* In order to get widget instance data we use a FluxCapacitor storage class | |
to connect shared data between the Widget and this metric controller */ | |
public FluxCapacitor capacitor { get; | |
set{ | |
installCapacitor(value); /* Plugin flux capacitor instance into the widget instance */ | |
} | |
} | |
public String metricVars { get; set; } | |
/* FYI: here is example of using capacitor */ | |
public getSomeParameter(){ | |
return capacitor.dashboard.accountWrapper; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public abstract with sharing class Widget{ | |
//========= INSTANCE VARS ==========// | |
public FluxCapacitor FC = new FluxCapacitor(); | |
/* NOTE: Custom solution for passing data to the metric components within a given widget instance */ | |
public PageReference repairErrors(){ | |
/*============= THIS ATTEMPT FAILS ==================*/ | |
try{ | |
Cache.OrgPartition customPartition = Cache.Org.getPartition('local.CustomData'); | |
customPartition.put('test', 'Widget.repairErrors()'); | |
}catch(Exception e){ System.debug('::CACHING ERROR:: '); } | |
return null; | |
} | |
//========= WRAPPER/CONTAINER CLASSES ============// | |
/* An exception class for widget data */ | |
public class WidgetException extends Exception{} | |
/* Parameter wrapper/container class */ | |
public class Parameter{ | |
public String source { get; set; } | |
public Integer year { get; set; } | |
public String field { get; set; } | |
public Boolean required { get; set; } | |
public Parameter(String source, Integer year, String field, String required){ | |
this.source = source; | |
this.year = year; | |
this.field = field; | |
this.required = (required=='true'||required=='1') ? TRUE : FALSE; | |
} | |
public Parameter(String source, Integer year, String field){ | |
this(source,year,field, 'FALSE'); | |
} | |
} | |
/* DataError wrapper/container class */ | |
public class DataError{ | |
public String field { get; set; } | |
public String index { get; set; } | |
public String source { get; set; } | |
public String message { get; set; } | |
public DataError(Widget widget, Parameter param, String message){ | |
this.message = message; | |
this.source = param.source; | |
this.index = param.year; | |
this.field = param.field; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<apex:component controller="Widget" layout="none"> | |
<apex:attribute name="data-controller" assignTo="{!Capacitor.dashboard}" description="shared data from the widget to the metric subcomponents" type="Dashboard" required="true"/> | |
<apex:attribute name="widget-type" assignTo="{!widgetType}" description="Type of widget component to be used [Component-Type]" type="String" required="true"/> | |
<apex:attribute name="widget-title" assignTo="{!title}" description="Title for the widget block" type="String" required="true"/> | |
<!-- Define Widget --> | |
<c:WidgetTitle widget="{!this}"/> | |
<!-- If there are errors, create a refresh button to attempt to get the data and cache it --> | |
<apex:outputPanel id="errorMessage" layout="block" rendered="{!IF(IsWidgetLoaded,FALSE,TRUE)}"> | |
<apex:form> | |
<apex:commandButton value="Refresh" action="{!repairErrors}" rerender="required_dummy_value" status="loadingWidgetData"/> | |
<!-- NOTE: "rerender" attribute required for "status" to work properly, some sort of salesforce bug --> | |
</apex:form> | |
</apex:outputPanel> | |
<!-- If there are no errors, attempt to load the metric component type that was requested when the widget was added to the page --> | |
<apex:outputPanel id="metric-components" layout="block" rendered="{!IF(IsWidgetLoaded,TRUE,FALSE)}"> | |
<!-- Include Gauge Components --> | |
<c:Gauge widget="{!this}" flux-capacitor="{!Capacitor}" rendered="{!IF(Component=='gauge',TRUE,FALSE)}"/> | |
<!-- Include Chart Components --> | |
<c:Chart widget="{!this}" flux-capacitor="{!Capacitor}" rendered="{!IF(Component=='chart',TRUE,FALSE)}" x-labels="{!labels}" data-grouping="{!groups}"/> | |
// etc, etc... | |
</apex:outputPanel> | |
</apex:component> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment