Sunday, 28 February 2016

Lightning Events Via Visualforce

This post is again as per request from one of my friend .He wanted me to put together a simple demonstration of how to handle lightning events from visualforce and how to publish or fire lightning events from outside salesforce .Both of these cases are extremely common if you are building application using lightning for visualforce .

If you have already started adopting Lightning component framework ,you probably know how important are Events .There are two types of events , Application events and Component Events .Please note that prerequisite for understanding this blog is understanding of events in context of lightning component framework .

The below code snippets apply to only application events .

Application events are handled by all components that are listening to the event. These events are essentially a traditional publish-subscribe model.


1. Firing Events from the Visualforce and Handling the Events in lightning components


To demonstrate this ,lets create a simple event file and fire the event from the visualforce inside the callback and handle the event back in the lightning component file

Below is the component set up for lightning framework

Lets put together the visualforce code needed for the experiment

Here are the exciting results











Now this opens a world of new opportunities to mash up already existing visualforce UI with lightning component framework.


One sample project that i experimented is in my git repo which takes map component as a lightning component but receives pickers from the visualforce select option .


2.Firing events from the lightning component and handling the event inside visualforce


This is another interesting observation ,you can fire an event from the lightning component and handle the event inside visualforce .

Lets see the hello world code for this scenario

The visualforce code is as below

Fun part




I hope this opens up a whole world of new directions to design and build some excellent mashups with visualforce and lightning .

Please reach out via my twitter @msrivastav13 or mail msrivastav13@gmail.com.

Introducing Lightning Base Components

Lightning Base Components are great addition to the platform and in fact revolutionary .One of the concerns around lightning component ...