Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.
Creating a CanvasLifecycleHandler
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, enter Apex Classes in the Quick Find box, then select Apex Classes.
- 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:
1public class MyCanvasLifecycleHandler 2implements Canvas.CanvasLifecycleHandler { 3 4 public Set<Canvas.ContextTypeEnum> excludeContextTypes(){ 5 Set<Canvas.ContextTypeEnum> excluded = new Set<Canvas.ContextTypeEnum>(); 6 7 // Code goes here to add items to excluded list 8 // that should be excluded from Context data 9 10 return excluded; 11 } 12 13 public void onRender(Canvas.RenderContext renderContext) { 14 15 // Code goes here to customize behavior when the app is rendered 16 17 } 18} - 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.