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
APN09217013342392059APN09217013342392059 

Salesforce1 publisher subscribe method

I have a publisher action of type "custom visualforce".

I am using Sfdc.canvas.publisher.subscribe method to know when the "submit" button on publisher is clicked.
I also want to know when the "cancel" button on the publisher is clicked.

I have below script in my VF page,

<script type='text/javascript'>
            Sfdc.canvas.publisher.subscribe({name: "publisher.post", onData:function(e) {
              
                console.log("Submit clicked");
             }});

            Sfdc.canvas.publisher.subscribe({name: "publisher.close", onData:function(e) {
             
                console.log("Cancel clicked");
             }});                                         
     </script>

When I click the submit button, I see successful log - "Submit Clicked"
But when I click the Cancel button nothing is logged.

Any idea how can I do this ?
There doesn't seem to be any documentation on different events that you can subscribe to.

AmitAmit (Salesforce Developers) 
Hello,

Following sample code can be used to override standard buttons.

<script type='text/javascript' src='/canvas/sdk/js/publisher.js'></script>
<script>
    Sfdc.canvas.publisher.subscribe({name: "publisher.showPanel",
        onData:function(e) {
            Sfdc.canvas.publisher.publish({name:"publisher.setValidForSubmit", payload:"true"});
    }});
    Sfdc.canvas.publisher.subscribe({ name: "publisher.post",
        onData: function(e) {
            alert("call some remote action here");
            Sfdc.canvas.publisher.publish({ name: "publisher.close",
                payload:{ refresh:"true" }});
    }});
</script>
khillan bhardwajkhillan bhardwaj
Hi Amit,

Can we hide or rename submit button from public action.

Thanks
Eric Kendi ShiraishiEric Kendi Shiraishi
Try using this:
Sfdc.canvas.publisher.subscribe({ name : "publisher.clearPanelState", 
    onData:function(e) {
        // Your code here
        alert('Fire ClearPanelState'); 
    }
});
This will run when the close event fires.

Regards