Presenting User Error Messages
You can use Canvas.CanvasRenderException to display error messages to the
user.
If you throw a CanvasRenderException from your onRender() implementation, the error message in that exception will be displayed to the user in the Salesforce UI. This exception will be managed only within the onRender() method.
CanvasRenderException supports all the standard Apex exception class methods and constructors. See ”Exception Class and Build-In Exceptions” in the Apex Code Developer Guide for more information on Apex exceptions.
Here’s an example onRender()
implementation that throws a Canvas.CanvasRenderException. Salesforce uses this exception
and displays “Error: Could not set URL” as the user error
message.
If
the canvas app is run from the Salesforce Chatter tab, the
error message resembles:
public void onRender(Canvas.RenderContext renderContext) {
// Code omitted that determines if the error condition occured
...
throw new Canvas.CanvasRenderException('Error: Could not set URL.');
}
