Filtering CanvasRequest Context Data

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

Salesforce calls your implementation of excludeContextTypes() to determine what context information is sent to your app. Your implementation returns a set of context data to exclude or returns null (or an empty set) if you need to receive all context data. The set consists of values from the Canvas.ContextTypeEnum Apex enum type.

The enum values are used as follows::

  • ORGANIZATION: Exclude context information about the organization in which the canvas app is running.
  • RECORD_DETAIL: Exclude context information about the object record on which the canvas app appears.
  • USER: Exclude context information about the current user.

Here’s an example excludeContextTypes() implementation that excludes the Organization and User context data:

1public Set<Canvas.ContextTypeEnum> excludeContextTypes(){
2    Set<Canvas.ContextTypeEnum> excluded = new Set<Canvas.ContextTypeEnum>();
3
4    // Exclude the Organization and User context data
5    excluded.add(Canvas.ContextTypeEnum.ORGANIZATION);
6    excluded.add(Canvas.ContextTypeEnum.USER);
7
8    return excluded;
9}

When your canvas app receives CanvasRequest Context data, the JSON data does not include the “organization” and “user” sections.

Reference documentation for the Apex Canvas.ContextTypeEnum is provided in the Apex Code Developer Guide.