---
schema_version: "1"
id: 1f97d52f63fabc58d15261de467549c9a9ed50c0fc6c04ca8e6205f45ef9ea69
title: Customizing Your App Lifecycle
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/platform/canvas-framework/guides/platform-connect/using/lifecycle/canvas-customizing-app-lifecycle.md
canonical_url: https://developer.salesforce.com/docs/platform/canvas-framework/guide/canvas-customizing-app-lifecycle.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 780cfeb826dd85cead68ff5161e7c5a2db19e922a0bd5a7a4c38d7c478b42b62
products:
  - Canvas Developer Guide
  - Platform Developer Content
---

# Customizing Your App Lifecycle

By providing a custom Apex class, you can control the context information that’s sent to your canvas app and add custom behavior when your app is rendered.

Salesforce provides several Apex interfaces and classes in the Canvas namespace that provide additional control over the canvas app lifecycle. You can use the Canvas namespace and the CanvasLifecycleHandler interface to:

-   Control what sections of the CanvasRequest Context data get sent to your app. You can, for example, require that Salesforce never send the [Organization](https://developer.salesforce.com/docs/platform/reference/organization-object.md) information in the CanvasRequest data. Excluding sections of context data improve performance by reducing the amount of data that’s sent in the request and remove the need to process the organization data in your app.
-   Retrieve application context data when the app is rendered and alter the behavior of your app accordingly. You can obtain the application version and, depending on the version, change how the app runs.
-   Modify some of the context data, such as the canvas app URL, custom parameters, or the list of object fields that are returned in the [Record](https://developer.salesforce.com/docs/platform/reference/record-object.md) data when the app is rendered.
-   Present a well-formed error message to the user in the Salesforce UI if something goes wrong.

Salesforce also provides a Test class in the Canvas namespace that you can use to create test context data and verify the behavior of your lifecycle handler without having to run your app.

Reference documentation for the Apex Canvas namespace is provided in the [Apex Code Developer Guide](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_intro_chapter.htm).

-   **[Creating a CanvasLifecycleHandler](https://developer.salesforce.com/docs/platform/canvas-framework/guide/canvas-creating-a-new-canvaslifecyclehandler.md)**  


    You can control your app lifecycle by providing an implementation of the Canvas.CanvasLifecycleHandler Apex interface that Salesforce can use.

-   **[Associating Your CanvasLifecycleHandler with Your App](https://developer.salesforce.com/docs/platform/canvas-framework/guide/canvas-associating-handler-with-app.md)**  


    After you’ve created an Apex implementation class for CanvasLifecycleHandler, you need to associate it with your canvas app by adding the class name to your canvas app configuration settings.

-   **[Filtering CanvasRequest Context Data](https://developer.salesforce.com/docs/platform/canvas-framework/guide/canvas-filtering-context-data.md)**  


    To filter out parts of the CanvasRequest Context data that gets sent to your canvas app, you need to provide an implementation of `Canvas.CanvasLifecycleHandler.excludeContextTypes()`.

-   **[Controlling Canvas App Behavior](https://developer.salesforce.com/docs/platform/canvas-framework/guide/canvas-controlling-app-behavior.md)**  


    To modify the default behavior of the signed request, you need to provide an Apex class that implements `Canvas.CanvasLifecycleHandler.onRender()` and associate this class with your canvas app. In your `onRender()` implementation, you can control app behavior with custom code.

-   **[Presenting User Error Messages](https://developer.salesforce.com/docs/platform/canvas-framework/guide/canvas-presenting-user-error-messages.md)**  


    You can use Canvas.CanvasRenderException to display error messages to the user.

-   **[Testing Your CanvasLifecycleHandler Implementation](https://developer.salesforce.com/docs/platform/canvas-framework/guide/canvas-testing-your-canvaslifecyclehandler.md)**  


    You can use the Canvas.Test class to test your `Canvas.CanvasLifecycleHandler.onRender()` implementation without having to run your canvas app.

-   **[Distributing Your CanvasLifecycleHandler Class](https://developer.salesforce.com/docs/platform/canvas-framework/guide/canvas-distributing-your-canvaslifecyclehandler.md)**  


    If you package and distribute your canvas app, make sure to include your CanvasLifecycleHandler class in your package.


