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.

Publishing a Canvas Event from a Visualforce Page

The following code example shows how to call the publish method to publish the myevent event from a Visualforce page. Any canvas app that subscribes to this event will receive the event.

1// Target all canvas apps.
2    Sfdc.canvas.controller.publish({name : 'mynamespace.myevent',
3                                    payload : {}});

The following code example shows how to call the publish method to publish an event to a specified canvas app from the Visualforce page.

If an event is published to specific canvas apps, even if other canvas apps on a Visualforce page are subscribed to it, only the canvas apps specified will receive that event. Using this code example, if the Visualforce page contained canvas apps app1, app2, and app3, and they all subscribed to myevent, only app1 would receive the event.

1// Target a specific canvas app
2    // where "app1" is the canvasId specified in the canvas component.
3    // For example: <apex:canvasApp canvasId="app1">
4    Sfdc.canvas.controller.publish({name : 'mynamespace.myevent',
5                                    payload : {}, 
6                                    target : {canvas : 'app1'}});

In the target parameter, you can specify multiple canvas apps by passing in an array of canvas apps: target : [{canvas : 'app1'}, {canvas: 'app2'}].