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 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 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.