Pages

Thursday, July 12, 2018

Adding Lightning Components in VF Page and Passing Values from URL

Can we create custom lightning components and use them in Salesforce Classic?

This question always comes in mind whenever we do development in Org which has not enabled lightning. We call these kind of Org as classic Salesforce Org.

We mainly create lightning components and use them in Lightning experience but it doesn't means that we can not utilize lightning components in Classic Salesforce (in VF)

If we have to create VF page, then create lightning components as per requirement and then add them in VF pages. So if in future, you migrate to Lightning from Salesforce Classic then you do not have to re-work on implementing VF functionality in Lightning.

Through this blog, I am going share sample code which explains how we can create lightning components and add it to VF pages. As lightning components works mainly based on attributes defined in component, how we can pass values to these attributes from VF page so that they behave as per requirement.

In below code, I am passing the Account Id and string message in VF page using URL parameters and then sending Account name and message to lightning component.

You can open VF page and specify parameters in URL. Below is sample URL:

/apex/SK_LtngCmpContainerVF?id=0019000001rHOgA&infoString=AccountId is passed from URL in VF and captured by component

or

/apex/SK_LtngCmpContainerVF?id=0019000001rHOgA&infoString=AccountId%20is%20passed%20from%20URL%20in%20VF%20and%20captured%20by%20component

Below is screenshot of VF page

Hope this will help!!!

No comments:

Post a Comment