---
schema_version: "1"
id: 61353fd416d30c27b46db91aa05cbafff68746cb9c77e288dded03cefb2646e9
title: CanvasLifecycleHandler Interface
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/apexref/apex_interface_canvas_CanvasLifecycleHandler.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_interface_canvas_CanvasLifecycleHandler.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: 61a55dccdfaba2a496e79a9153e8ef12a7cc54a89f1d80d4c9c348ab3a2c1f25
description: Implement this interface to control context information and add custom behavior during the application render phase.
---
# CanvasLifecycleHandler Interface

Implement this interface to control context information and add custom behavior during the application render phase.

## Namespace

[Canvas](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_namespace_Canvas.htm "The Canvas namespace provides an interface and classes for canvas apps in Salesforce.")

## Usage

Use this interface to specify what canvas context information is provided to your app by implementing the excludeContextTypes() method. Use this interface to call custom code when the app is rendered by implementing the onRender() method.

If you provide an implementation of this interface, you must implement excludeContextTypes() and onRender().

## Example Implementation

The following example shows a simple implementation of CanvasLifecycleHandler that specifies that organization context information will be excluded and prints a debug message when the app is rendered.

public with sharing class MyCanvasListener 
implements Canvas.CanvasLifecycleHandler{
    public Set<Canvas.ContextTypeEnum> excludeContextTypes(){
        Set<Canvas.ContextTypeEnum> excluded = new Set<Canvas.ContextTypeEnum>();
        excluded.add(Canvas.ContextTypeEnum.ORGANIZATION);
        return excluded;
    }
    
    public void onRender(Canvas.RenderContext renderContext){
        System.debug('Canvas lifecycle called.');
    }
}

- **[CanvasLifecycleHandler Methods](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_canvas_CanvasLifecycleHandler_methods.htm)**

#### See Also

- [_Canvas Developer Guide_: Customizing Your App Lifecycle](https://developer.salesforce.com/docs/atlas.en-us.264.0.platform_connect.meta/platform_connect/canvas_customizing_app_lifecycle.htm "Canvas Developer Guide: Customizing Your App
    Lifecycle - HTML (New Window)")