{"id":5737,"date":"2016-09-22T17:40:16","date_gmt":"2016-09-22T17:40:16","guid":{"rendered":"http:\/\/www.jitendrazaa.com\/blog\/?p=5737"},"modified":"2017-04-05T11:48:40","modified_gmt":"2017-04-05T11:48:40","slug":"use-lightning-component-in-visualforce-page","status":"publish","type":"post","link":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/use-lightning-component-in-visualforce-page\/","title":{"rendered":"Use Lightning Component in Visualforce Page"},"content":{"rendered":"<p style=\"text-align: justify;\">In all of my projects currently, I have stopped creating Visualforce code. well, thats partially correct ;). I still need Visualforce page because most my clients are still on classic \/ Aloha Salesforce. However, If you have noticed, all Salesforce release notes, talks, webinars, Dreamforce focuses on Lightning experience. And I can say\u00a0with confidence that Lightning is really really very cool. Sky is limit to your imagination, You can unleash hidden talent within you. Well, all talk talk&#8230; and you may be thinking, how can I start with Lightning Component? My client don&#8217;t even want to move away from classic. Its lots of work and money for them.<\/p>\n<p style=\"text-align: justify;\">Well, here is an Idea what I am doing. I still uses Salesforce classic, still uses Visualforce but behind the scene, magic&#8230; tadaaa , Lightning Component. I will show walk you through this, how its being done.<\/p>\n<p style=\"text-align: justify;\">We will use existing <a href=\"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/flipcard-lightning-component\/\">Flipcard Lightning Component<\/a> to display on Visualforce page. Once Lightning Component is created, we need to create a Lightning Application to act an as a container.<!--more--><\/p>\n<p><span style=\"text-decoration: underline;\">LightningOutContainerApp.app<\/span><\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;aura:application access=&quot;GLOBAL&quot; extends=&quot;ltng:outApp&quot;&gt;\r\n\t&lt;aura:dependency resource=&quot;c:FlipCard&quot;\/&gt;\r\n&lt;\/aura:application&gt;\r\n<\/pre>\n<p style=\"text-align: justify;\">In above Lightning Application, we have used access as global so that it can be used anywhere in Salesforce organization like Visualforce. extending\u00a0<strong>ltng:outApp<\/strong> indicates that any component defined in this application can be used on Visualforce page.<\/p>\n<blockquote>\n<p style=\"text-align: justify;\">Extending from <strong>ltng:outApp<\/strong> adds SLDS resources to the page to allow your Lightning components to be styled with the Salesforce Lightning Design System (SLDS). If you don\u2019t want SLDS resources added to the page, extend from <strong>ltng:outAppUnstyled<\/strong> instead.<\/p>\n<\/blockquote>\n<p style=\"text-align: justify;\">Next step is to create a Visualforce page where we want to display Lightning Component.<\/p>\n<p><span style=\"text-decoration: underline;\">LightningOutDemo.vf<\/span><\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;apex:page &gt;\r\n &lt;apex:includeLightning \/&gt;\r\n\r\n &lt;div style=&quot;width:30%;height:100px;&quot; id=&quot;FlipcardContainer&quot; \/&gt;\r\n\r\n &lt;script&gt;\r\n $Lightning.use(&quot;c:LightningOutContainerApp&quot;, function() {\r\n $Lightning.createComponent(&quot;c:FlipCard&quot;,\r\n { \r\n borderColor : &quot;#16325c&quot;, \r\n bgColor : &quot;#16325c&quot; ,\r\n fontColor : &quot;#FFF&quot;,\r\n frontText : &quot;What's cool about Lightning Component Development&quot;,\r\n backText : &quot;You dont need to enable Lightning experience, It will work on Classic Instance as well&quot;\r\n },\r\n &quot;FlipcardContainer&quot;,\r\n function(cmp) {\r\n console.log('Component created, do something cool here');\r\n });\r\n });\r\n &lt;\/script&gt;\r\n&lt;\/apex:page&gt;\r\n<\/pre>\n<p style=\"text-align: justify;\">In above Visualforce page,\u00a0<strong>apex:includeLightning <\/strong>tag\u00a0imports necessary dependencies and scripts to enable Visualforce to act as Lightning component container.<\/p>\n<p style=\"text-align: justify;\"><strong>$Lightning.use()<\/strong> method in JavaScript is used to refer Lightning Application which extends <em>ltng:outApp<\/em>.\u00a0<strong>$Lightning.createComponent<\/strong> is used to create Lightning Component dynamically.<\/p>\n<p style=\"text-align: justify;\">We\u00a0can call <strong>$Lightning.use()<\/strong> multiple times on a page, but all calls must reference the same Lightning dependency app.<\/p>\n<p><strong>Reference<\/strong><\/p>\n<ul>\n<li><a href=\"https:\/\/developer.salesforce.com\/docs\/atlas.en-us.lightning.meta\/lightning\/components_visualforce.htm\">Salesforce documentation<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>How to use Lightning Out to surface Lightning Component on Visualforce Pages<\/p>\n","protected":false},"author":1,"featured_media":5744,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"jz_research_post":"","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[9],"tags":[311,391],"class_list":["post-5737","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-salesforce","tag-lightning-component","tag-lightning-out"],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2016\/09\/Use-Lightning-Components-in-Visualforce-Pages.jpg?fit=862%2C501&ssl=1","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":4102,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/salesforce-faq-part-20-lightning-questions\/","url_meta":{"origin":5737,"position":0},"title":"Salesforce interview question related to Lightning framework &#8211; Part 20","author":"Jitendra","date":"February 4, 2015","format":false,"excerpt":"Salesforce interview questions for Salesforce developers and admin , mostly related to newly released Salesforce Lightning components and applications","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":6222,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/use-visualforce-in-classic-and-lightning-experience\/","url_meta":{"origin":5737,"position":1},"title":"Use Visualforce in Classic and Lightning Experience","author":"Jitendra","date":"August 29, 2017","format":false,"excerpt":"How to design a Visualforce page so that It would be displayed properly in classic as well in Salesforce Lightning Experience","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"Same Visualforce in classic and Lightning","src":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2017\/08\/Same-Visiualforce-in-classic-and-Lightning.gif?fit=924%2C572&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2017\/08\/Same-Visiualforce-in-classic-and-Lightning.gif?fit=924%2C572&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2017\/08\/Same-Visiualforce-in-classic-and-Lightning.gif?fit=924%2C572&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2017\/08\/Same-Visiualforce-in-classic-and-Lightning.gif?fit=924%2C572&ssl=1&resize=700%2C400 2x"},"classes":[]},{"id":6880,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/get-current-user-id-in-salesforce\/","url_meta":{"origin":5737,"position":2},"title":"Get Current User Id in Salesforce","author":"Jitendra","date":"February 2, 2019","format":false,"excerpt":"How to get Current Logged in user Id in Apex, Visualforce, Lightning Component and Formula fields in Salesforce","rel":"","context":"In &quot;Lightning&quot;","block_context":{"text":"Lightning","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/lightning\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":6920,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/data-exchange-between-aura-lightning-web-components-lwc-and-visualforce\/","url_meta":{"origin":5737,"position":3},"title":"Event Handling between Aura, Lightning Web Components (LWC) and Visualforce","author":"Jitendra","date":"October 16, 2019","format":false,"excerpt":"How to use Lightning Message Services for event handling between Lightning Web Components, Aura Components and Visualforce","rel":"","context":"In &quot;Lightning&quot;","block_context":{"text":"Lightning","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/lightning\/"},"img":{"alt_text":"Salesforce Lightning Message Service","src":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2019\/10\/Salesforce-Lightning-Message-Service.png?fit=1200%2C1046&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2019\/10\/Salesforce-Lightning-Message-Service.png?fit=1200%2C1046&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2019\/10\/Salesforce-Lightning-Message-Service.png?fit=1200%2C1046&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2019\/10\/Salesforce-Lightning-Message-Service.png?fit=1200%2C1046&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2019\/10\/Salesforce-Lightning-Message-Service.png?fit=1200%2C1046&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":6232,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/winter-18-automatic-styling-of-visualforce-pages-in-lightning-experience\/","url_meta":{"origin":5737,"position":4},"title":"Winter 18 &#8211; Automatic Styling of Visualforce Pages in Lightning Experience","author":"Jitendra","date":"September 6, 2017","format":false,"excerpt":"How to use lightningStylesheets attribute to render Visualforce in Lightning Experience Stylesheet","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"Winter 18 - Automatic Styling of Visualforce Pages in Lightning Experience","src":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2017\/09\/Winter-18.gif?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2017\/09\/Winter-18.gif?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2017\/09\/Winter-18.gif?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":6142,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/show-lightning-component-on-public-website-without-authentication\/","url_meta":{"origin":5737,"position":5},"title":"Show Lightning component on public website without authentication","author":"Jitendra","date":"June 5, 2017","format":false,"excerpt":"How to show Lightning component on public sites without need of user authentication","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/5737","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/comments?post=5737"}],"version-history":[{"count":8,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/5737\/revisions"}],"predecessor-version":[{"id":5747,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/5737\/revisions\/5747"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/media\/5744"}],"wp:attachment":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/media?parent=5737"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/categories?post=5737"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/tags?post=5737"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}