Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.
getEnvironmentContext()
Signature
public Canvas.EnvironmentContext getEnvironmentContext()
Return Value
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}