Check this code,I have added this as publisher action on opportunities. When I press cancel button it works for the first time – takes me to opportunity detail page. But when I try again – I stay at the same page and the navigation doesnt work.

Any help would be greatly appreciated.

function myCloseWindow() {
       if ( (typeof window.sforce != 'undefined') && (window.sforce!=null) && (sforce.one != null)  )  {


    <apex:commandbutton value="cancel" onclick="myCloseWindow();"/> 

  • Is window.sforce or sforce.one undefined? – GrayB Nov 2 '15 at 19:59
  • I changed the code to if ( (typeof sforce != 'undefined') && (sforce != null) ), that doesnt work as well. – Lx123 Nov 2 '15 at 20:34
  • if you are passing object id then you can also use method navigateToSObject. – Tushar Sharma Nov 3 '15 at 5:02

I would suggest not to use command link at all as it may cause other issues with form and instead go with pure HTML for these types of actions

 <a href="#" onclick="myCloseWindow();"> Cancel </a>

Also add redirect parameter to true in case its caching

function myCloseWindow() {
   if ( (typeof window.sforce != 'undefined') && (window.sforce!=null) && (sforce.one != null)  )  {



Update :

After long conversation and digging into what author of question is trying ..Since its opened from publisher actions rather than VF its ideal to use Canvas SDK for all the operations

   <apex:page docType="html-5.0" showHeader="false" sidebar="false" standardStylesheets="false"> 
    <meta charset="UTF-8" /> 
    <apex:includeScript value="/canvas/sdk/js/publisher.js" />
      function closeAction() { 
       Sfdc.canvas.publisher.publish({ name : "publisher.close", payload : {    refresh:"true" }}); 
     <h1>Sample Page</h1>
     <button onclick="closeAction()">Close Action</button>
  • Thanks Mohit, I replaced command button with your code - again the same problem. Worked for first time Only. Have you tried copy pasting the code in your org and see what happens? – Lx123 Nov 2 '15 at 21:22
  • let me see ...I will try in my org and let you know .Thanks – Mohith Shrivastava Nov 2 '15 at 21:40
  • Are you checking inside SF1 container? – Mohith Shrivastava Nov 2 '15 at 21:43
  • I logged into SF1 on browser using Android device. Checked on salesforce simulator (downloadable from Chrome app store) - same results. – Lx123 Nov 2 '15 at 21:46
  • I checked it and its working as expected ... – Mohith Shrivastava Nov 2 '15 at 21:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.