getEnvironmentContext()

Retrieves the environment context information.

Signature

public Canvas.EnvironmentContext getEnvironmentContext()

Return Value

Type: Canvas.EnvironmentContext

Usage

Use this method to get the environment context information for your canvas app.

Example

The following example implementation of the CanvasLifecycleHandler onRender() method uses the provided RenderContext to retrieve the environment context information and then modifies the custom parameters.

1public void onRender(Canvas.RenderContext renderContext) {
2   Canvas.EnvironmentContext env = 
3        renderContext.getEnvironmentContext();
4        
5    // Retrieve the custom params
6    Map<String, Object> previousParams = (Map<String, Object>)
7          JSON.deserializeUntyped(env.getParametersAsJSON());
8
9    previousParams.put('param1',1);
10    previousParams.put('param2',3.14159);
11
12    ...
13
14    // Now, add in some opportunity record IDs
15    Opportunity[] o = [select id, name from opportunity];
16    previousParams.put('opportunities',o);
17
18    // Now, replace the parameters
19    env.setParametersAsJSON(JSON.serialize(previousParams));
20}