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.

setParametersAsJSON(jsonString)

Sets the custom parameters for the canvas app.

Signature

public void setParametersAsJSON(String jsonString)

Parameters

  • jsonString:

    Type: String

    The custom parameters that you need to set, serialized into a JSON format string.

Return Value

Type: Void

Usage

Use this method to set the current custom parameters for the canvas app. The parameters must be provided in a JSON string. You can use the System.JSON.serialize(objectToSerialize) method to serialize a map into a JSON string.

Setting the custom parameters will overwrite the custom parameters that are set for the current request. If you need to modify the current custom parameters, first get the current set of custom parameters by using getParametersAsJSON(), modify the retrieved parameter set as needed, and then use this modified set in your call to setParametersAsJSON().

If the provided JSON string exceeds 32KB, a System.CanvasException will be thrown.

Example

This example gets the current custom parameters, adds a new newCustomParam parameter with a value of ‘TESTVALUE’, and sets the current custom parameters.

1Canvas.EnvironmentContext env = renderContext.getEnvironmentContext();
2
3// Get current custom params
4Map<String, Object> previousParams = 
5    (Map<String, Object>) JSON.deserializeUntyped(env.getParametersAsJSON());
6
7// Add a new custom param
8previousParams.put('newCustomParam','TESTVALUE');
9
10// Now replace the parameters with the current parameters plus our new custom param
11env.setParametersAsJSON(JSON.serialize(previousParams));