

I like this approach because the Lightning component is decoupled from the host and communicates via events. If it doesn’t exist, the page is running in Classic mode, and window.location is used instead. If the object exists, is invoked to go to the given sObject’s home page. It adds a handler for force:navigateToObjectHome which detects the presence of the sforce.one object.
SALESFORCE IFRAME CODE
The code snippet above is from a VF page hosting a component named customObjectEdit. For example, window.location may be set with the proper URL corresponding to the type of event.

Handlers have to detect this scenario and provide an alternate means to navigate. Salesforce Classic, on the other hand, does not run app.one. Internally sforce.one uses window.postMessage() to send messages to the parent frame which in turn forwards the events to the app.one container. This library provides methods for navigation.

The Lightning Experience (and Salesforce1) provides a JavaScript helper library called sforce.one. How it handles these events depends on whether the page is running in the Lightning Experience or Salesforce Classic. This means any VF page hosting a Lightning component will have to explicitly handle navigation events raised by the component and any dependencies. The app.one host comes with built-in listeners that properly handle all the force events, but a VF page is either isolated in its own iframe (Lightning Experience) or running outside of Lightning (Salesforce Classic). Handling Navigation EventsĪt this point, events are firing, but nothing is listening. This brings us to the second step which is to add event handlers in the VF host page. With this change, the navigation events will fire properly in your components however, there’s still a problem. Add the force dependency to your Lightning dependency app. The issue is the force.* events are not recognized as a dependency by Lightning Out. The event variable is null because $A.get() can’t find the event type. The Lightning code below will throw an error when run in a VF page. The first step is to get the navigation events firing properly. Events are handled explicitly in the Lightning Out host where the environment detection logic is isolated. Instead, components continue to raise events as usual and are still decoupled from the environment. My approach avoids the need to detect the host environment inside of a component.
SALESFORCE IFRAME HOW TO
In this post, I discuss how to get navigation events working in a Lightning Out host like a VF page. Events raised in the VF page stop at the iframe boundary and don’t bubble up into the parent frame. Navigation events like force:navigateToObjectHome are handled by the one.app container in the parent frame. The problem is VF pages are loaded into an iframe element in the Lightning Experience. In my previous post, I covered how to use a Lightning component in a Visualforce (VF) page and mentioned an issue with navigation events.
