1

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)  )  {

            sforce.one.navigateToURL('/006XXXXXXXXX');
        }


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

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

1 Answer 1

1

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)  )  {

        sforce.one.navigateToURL('/006XXXXXXXXX',true);
    }

}

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" />
    <script>
      function closeAction() { 
       Sfdc.canvas.publisher.publish({ name : "publisher.close", payload : {    refresh:"true" }}); 
    }
     <h1>Sample Page</h1>
     <button onclick="closeAction()">Close Action</button>
    </apex:page>
8
  • 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
    Commented Nov 2, 2015 at 21:22
  • let me see ...I will try in my org and let you know .Thanks Commented Nov 2, 2015 at 21:40
  • Are you checking inside SF1 container? Commented Nov 2, 2015 at 21:43
  • I logged into SF1 on browser using Android device. Checked on salesforce simulator (downloadable from Chrome app store) - same results.
    – Lx123
    Commented Nov 2, 2015 at 21:46
  • I checked it and its working as expected ... Commented Nov 2, 2015 at 21:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .