Print this page

Lightning Component embedded on a Visual Force page throwing Stale Session Exception Error

Knowledge Article Number 000232461
Description A stale session exception error can be thrown if you are working with Lightning components embedded on a visual force page. One reason for such behaviour is that the current session information will be lost when you are moving from to lighting framework (based on Open source Aura Framework) to the visualforce framework and a server-side call is not defined in the lighting component controller.

For example, let’s say that you created a Lighting component which contains a button, but this button is not bound to any action. Once you embed such a component onto a Visual Force page, the button will be render in the browser but if you click on it, the stale session exception error will be thrown.

Lightning Button Code
Lightning Button Code

Lightning Component embedded on Visual Force Page
Lightning Component Embedded on Visual Force Page

Stale Session Exception Error Thrown after clicking on button 
Stale Session Exception

Resolution Let’s fix this issue, first you need to create a server-side action that is going to be called when you press the button. For this example I created a function called getInput() which displays an alert message but most importantly performs a server-side action call.

Now if we press on the new button, the session information is maintained between frameworks and the alert message is displayed on the browser.

Lightning Button Code
Lightning Button with Function call

Lightning Component Controller function with Server-Side Call
Server-Side Call Function

Same Lightning Component with working Button
 Working Lightning Component

promote demote