4

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

6
  • 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, 2016 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 :/ Nov 9, 2016 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, 2016 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 ? Nov 12, 2016 at 11:44
  • I tried window.top.location.href = '/'+sfdcRecordId ; , same result, even slower coz there is url rewriting in addition Nov 12, 2016 at 11:48

2 Answers 2

4

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.

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

We should try the standard function - sforce.one.navigateToSObject(recordId, 'detail');

For reference: https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/salesforce1_dev_jsapi_sforce_one.htm

1
  • 1
    Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Nov 25, 2022 at 16:10

You must log in to answer this question.

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