1

From a component included in a vf page, I need to open the record page in the SFDC CRM application ( one.app ).

I tried using force:navigateToSObject but is not working when called from a vf page including a ltng:outApp component, probably because vf page is technically in an iFrame.

It is also not possible to update the hash so when detected it opens the good record page layout ( iFrame prevent top frame url hash update )

Only solution for now is window.top.location.href = '/one/one.app#/sObject/'+sfdcRecordId+'/view' , but :

  • it provokes a full refresh of the page ( 5 seconds of snowman )
  • I'm pretty sure it won't work with LockerService activated

Would anyone have a magic solution ? ( of SFDC an evol to announce ? :) )

Many thanks

  • Do you need to use that event? Using a traditional a tag should work. The one.app container will catch the navigation and go to the sObject record. – dsharrison Nov 8 '16 at 23:59
  • I need to use an event (or anything triggered via javascript) , I have synchronization between remote system data and SFObjects between the user click and the record layout display ... at the moment of the click, sometimes the Record doesn't exist yet in SObjects :/ – Nicolas Vuillamy Nov 9 '16 at 0:03
  • Try just using window.location then to navigate to /recordId, I believe this will get handled the same as an href. – dsharrison Nov 9 '16 at 0:40
  • In my question I describe that this is what I currently do, and it provokes a refresh with loading snowman. window.top.location.href = '/one/one.app#/sObject/'+ActionDetail.sfdcRecordId+'/view' ; Do you mean something else ? – Nicolas Vuillamy Nov 12 '16 at 11:44
  • I tried window.top.location.href = '/'+sfdcRecordId ; , same result, even slower coz there is url rewriting in addition – Nicolas Vuillamy Nov 12 '16 at 11:48
3

There is something special about an anchor tag href that is handled by the one.app container when triggered from an iframed Visualforce page. I am not sure what this is (maybe someone could chime in if they know), but the following works for me even with locker service enabled:

<apex:page>

  <a href="javascript:void(0);" onclick="ns.doNav()">Do Nav</a>

  <span style="display: none">
    <a id="stdNav" href="">Navigate</a>
  </span>


  <script>
      (function(ns, undefined) {

          ns.location = '/001E000001hcTcO';

          ns.doNav = function() {
             var anchorEl = document.getElementById('stdNav');
             anchorEl.href = ns.location;
             anchorEl.click();
          }
      })(window.ns = window.ns || {});

  </script>
</apex:page>

By updating the href of our hidden link then triggering the click event, the one.app container navigates to the record view page without a reload of the app. Note that depending on which browsers you need to support you may need to feature detect the .click() function and add some additional support there for other browser cases.

-D.S.

  • It works like a charm, many many many many thanks :) :) – Nicolas Vuillamy Nov 13 '16 at 11:59
  • Glad to hear that this worked for you! – dsharrison Nov 16 '16 at 16:35

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.