function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Jordan SewellJordan Sewell 

Publishing a canvas event from a Visualforce Page

I've got a canvas app in a developer org that is pointing to another org's visualforce page and I'm trying to publish an event from the VF page to the canvas app. I get the following error:

"Uncaught TypeError: Cannot read property 'publish' of undefined" - which is caused by a line in the controller.js
function publish(event) {
      Sfdc.canvas.parent.publish(event)
    }

Here is the code for the VF page that contains the canvas app (subscriber)
<apex:page showHeader="true" sidebar="true">
    <script type="text/javascript" src="https://na24.salesforce.com/canvas/sdk/js/33.0/canvas-all.js"/>
    <script type="text/javascript" src="/canvas/sdk/js/31.0/controller.js"></script>   
    <apex:canvasApp applicationName="testApp" />
    <script>
    // Subscribe to a custom event.
        Sfdc.canvas.controller.subscribe({name : 'mynamespace.myevent',onData : function (e) {console.log(e);}});
    </script>
</apex:page>
And here's the code for the VF page contained in the canvas app:
<apex:page showHeader="false" sidebar="false">
<apex:includeScript value="/canvas/sdk/js/33.0/canvas-all.js"/>
<script type="text/javascript" src="/canvas/sdk/js/31.0/controller.js"></script>   

<script>
	//publish attempt
  function testpayload () { 
    Sfdc.canvas.controller.publish({name : 'mynamespace.myevent',payload : {}});
  }
</script>
<h4>Canvas Testing</h4>
<br/>
<input type="button" value="Test" onclick="testpayload();"/>
</apex:page>
What am I missing? What needs to be included in the publishing VF page so that the parent in the canvas object is defined?

-Jimmy
 
tlfutlfu
I don't profess to be a Canvas expert, as I am just delving into this myself, but I don't really think what you are doing is a valid usage of Canvas. The Canvas app and the VF page that contains run within the same org. This allows the Canvas app and VF page to interact with one another using events. I don't think you can "publish" from a VF page in one org, to a Canvas app living in another VF page in another org. I believe the "publish" operation is failing, because the VF page that is calling publish does not include the apex:canvasApp tag.