public void setParametersAsJSON(String jsonString)
Type: Void
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.
This example gets the current custom parameters, adds a new newCustomParam parameter with a value of ‘TESTVALUE’, and sets the current custom parameters.
Canvas.EnvironmentContext env = renderContext.getEnvironmentContext(); // Get current custom params Map<String, Object> previousParams = (Map<String, Object>) JSON.deserializeUntyped(env.getParametersAsJSON()); // Add a new custom param previousParams.put('newCustomParam','TESTVALUE'); // Now replace the parameters with the current parameters plus our new custom param env.setParametersAsJSON(JSON.serialize(previousParams));