SalesforceSummaries: a series delivering key insights from Salesforce YouTube videos, to save you time as you keep up to date with the latest technological changes within the Salesforce ecosystem.
Visualforce and Lightning can be used to compliment each other to deliver compelling pages. This has become easier than ever with the introduction of the lightningStylesheets attribute in Visualforce, that upgrades the styling of a page to look like Lightning. In the past, it was more challenging and time intensive to upgrade a Visualforce page to Lightning however, the introduction of the lightningStylesheets attribute makes it easier than ever to upgrade a Visualforce page to have the Lightning feel and design.
Furthermore, by using Lightning Out, you can leverage standard and custom Lightning components in Visualforce pages to deliver an even more compelling user experience.
The slides and code for this presentation can be found here.
Details: ‘Visualforce in Lightning Experience’
Presenter: Mike Senn
Time: 30 minutes
Key Terms: Visualforce, Lightning, Lightning Out, native UX
[email protected] — There are three topics in this discussion.
The first topic is to show that there are a variety of ways to use Visualforce in Lightning Experience (LEX). These are either in Lighting tabs, page layouts, custom actions and standard actions.
The second topic is to demo a new Visualforce tag that will style a Visualforce page just like a Lightning page very quickly and easily. In contrast, as per this video that was summarized here, in the past, it was quite a lengthy process to migrate a Visualforce page to have Lightning styling. So by simply leveraging the lightingStyleSheets tag in your Visualforce pages is a huge efficiency win.
The third topic is about how you can bring Lightning into Visualforce via Lightning Out.
[email protected] — There are many different ways in which Visualforce works in Lightning.
[email protected] — This Lighting tab shows a Visualforce page. The orange dotted border represents a Visualforce page. And so a Visualforce page can be displayed in Lightning Experience (LEX) on a tab.
[email protected] — Upon clicking on the frog icon, the user will be navigated to the Lightning record page for the campaign.
So you can see here that Visualforce is being used in a standard Lightning page layout and as a small part of the page layout, as the rest of the page is a Lightning component.
Upon clicking this button, a Visualforce page will be navigated to. Again, everything within the orange border is a Visualforce page and so we can see that the Visualforce page is taking up most of this Lightning page.
The Visualforce page has a related list with multiple columns and then 3 different columns below which contain different information and one Visualforce chart. To accomplish something like this isn’t possible with the standard Lightning page layout.
[email protected] — You can also override a standard action in LEX with a Visualforce page.
[email protected] — You can also use a Visualforce component on a Lightning page via the Lightning app builder.
[email protected] — With the lightningStyleSheets tag, it’s possible to quickly and easily upgrade the look and feel of a Visualforce page to look like a Lightning page.
[email protected] — To upgrade a Visualforce page to match the style of a Lightning page, simply add the relevant tag (lightningStylesheets=”true”).
[email protected] — Having made this change, the page looks vastly different now:
[email protected] — For users who don’t have the Lightning Experience user permission, they would still see such a page as it would look like in Classic.
[email protected] — By leveraging the lightningStylesheets tag, you’ll notice that the font size will tend be larger and at certain browser widths, the text may run into each other. And so you shouldn’t just turn this tag on for every page and expect it to work seamlessly without doing any testing.
However, by leveraging this tag, the Visualforce page will follow the SLDS design.
[email protected] — Some notes on leveraging the tag are:
[email protected] — You can use conditional styling in your Visualforce pages to render specific styling.
[email protected] — It’s important to note some subtle differences when developing Visualforce pages for a Lightning Experience. If you’re creating a Visualforce page for Lightning, you’ll have to create a Visualforce tab first.
[email protected] — You can use Lightning Out to bring standard and custom Lightning components into Visualforce. This way, you can have a Visualforce page that looks a lot more like Lightning. By using the aforementioned lightningStylesheets tag, you can get 70% of the way there (in terms of migrating a VF page to a Lightning style) but you can get the other 30% of the way there via Lightning Out.
[email protected] — There are 3 steps to using Lightning Out. You first have to create a Lightning dependency application, then load the dependency app in the Visualforce page and finally create the Lightning components for your page. In this example, the force:recordView component will be displayed in a Visualforce page. This particular component represents a read-only view of a record. In the above screenshot, the force:recordView component is the component that says ‘Charles Bleakley’.
[email protected] — This is the Lightning dependency application; which defines all of the Lightning components that will be defined in the Visualforce page. In the below example, only one standard Lightning component is defined however, you can have multiple standard and even custom Lightning components defined.
[email protected] — The above screenshot shows a Lightning aura application that extends the Lightning out application: — extends=”ltng:outApp”. This tells the Lightning app that this is a Lightning out app that will use the standard force:recordView component.
[email protected] — For the second step — loading the dependency app in the Visualforce page — this is achieved by loading the Lightning app library into the Visualforce page via the apex:includeLightning/ component.
[email protected] — Then an empty div with an Id is defined as per line 11 of the code. It’s important to give this empty div an Id as this is where the standard component, as defined in the Lightning Out application, will be displayed.
In the code above, the first parameter passed is the reference to the Lightning app and the second parameter is a callback function, which will be called whenever the dependency app has been loaded.
[email protected] — The callback function defines any attributes that the Lightning component must have during initialization.
The standard Lightning component force:recordView must have 2 attributes: the recordId and type. The recordId is the id of the record to load and the type attribute is the type of layout to use to display the record. Possible values are FULL or MINI. The default is MINI.
[email protected] — Finally, the $Lightning.createComponent is called to create the Lightning component. An empty callback is also passed. You could pass in a callback to deal with event handlers to the Lightning component etc. But that isn’t required in this example because the force:recordView component is a read-only component.
[email protected] — And now, upon refreshing the Visualforce page, we can see the force:recordView component displayed. This is how you can combine standard and custom Lightning components into a Visualforce page with the lightningStylesheets.
[email protected] — By turning on lightningStylesheets in the Visualforce page, the impact is that the page has been re-designed and looks more native to Lightning.
[email protected] — A summary of the steps that were taken are: