Newer Version Available
Creating a CanvasLifecycleHandler
You can control your app lifecycle by providing an implementation
of the Canvas.CanvasLifecycleHandler Apex interface that Salesforce can use.
The Apex Canvas.CanvasLifecycleHandler interface provides methods and callbacks for customizing app lifecycle behavior. Salesforce will use your implementation at runtime to let you run custom code. Use the following steps to create an implementation of the Canvas.CanvasLifecycleHandler interface.
- From Setup, click .
- Click New to create a Apex class.
-
Create an Apex class that implements the Canvas.CanvasLifecycleHandler interface.
You must implement the excludeContextTypes() and onRender() methods.
Here’s a template example:
1swfobject.registerObject("clippy.codeblock-0", "9"); 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17public class MyCanvasLifecycleHandler 18implements Canvas.CanvasLifecycleHandler { 19 20 public Set<Canvas.ContextTypeEnum> excludeContextTypes(){ 21 Set<Canvas.ContextTypeEnum> excluded = new Set<Canvas.ContextTypeEnum>(); 22 23 // Code goes here to add items to excluded list 24 // that should be excluded from Context data 25 26 return excluded; 27 } 28 29 public void onRender(Canvas.RenderContext renderContext) { 30 31 // Code goes here to customize behavior when the app is rendered 32 33 } 34} - After you’ve finished adding your code, save the Apex class.
- Optionally test your implementation by using the Canvas.Test class.
- To let Salesforce know which implementation to use for your app, associate your Apex class with your app.