• WHO WE ARE
  • WHAT WE DO
    • Salesforce
      • Implementations
        • Sales Cloud
        • Service Cloud
        • CPQ
        • Field Service Lightning
        • Field Service for SMEs
      • Developments
        • Salesforce Customization
        • Custom Application Development
        • AppExchange Product Development
      • Migrations
        • Classic to Lightning Migration
        • Other Systems to Salesforce Migration
      • Integrations
    • Data Science
      • BI Solutions
      • AI/ML solutions
      • Agentic AI
  • HOW WE DO
    • Delivery Model
    • Our Works
  • REACH US
    • Contact Us
    • Careers
  • BLOG
    • WHO WE ARE
    • WHAT WE DO
      • Salesforce
        • Implementations
          • Sales Cloud
          • Service Cloud
          • CPQ
          • Field Service Lightning
          • Field Service for SMEs
        • Developments
          • Salesforce Customization
          • Custom Application Development
          • AppExchange Product Development
        • Migrations
          • Classic to Lightning Migration
          • Other Systems to Salesforce Migration
        • Integrations
      • Data Science
        • BI Solutions
        • AI/ML solutions
        • Agentic AI
    • HOW WE DO
      • Delivery Model
      • Our Works
    • REACH US
      • Contact Us
      • Careers
    • BLOG
  • [email protected]
  • (+91) 44-49521562
Merfantz - Salesforce Solutions for SMEs
Merfantz - Salesforce Solutions for SMEs
  • WHO WE ARE
  • WHAT WE DO
    • Salesforce
      • Implementations
        • Sales Cloud
        • Service Cloud
        • CPQ
        • Field Service Lightning
        • Field Service for SMEs
      • Developments
        • Salesforce Customization
        • Custom Application Development
        • AppExchange Product Development
      • Migrations
        • Classic to Lightning Migration
        • Other Systems to Salesforce Migration
      • Integrations
    • Data Science
      • BI Solutions
      • AI/ML solutions
      • Agentic AI
  • HOW WE DO
    • Delivery Model
    • Our Works
  • REACH US
    • Contact Us
    • Careers
  • BLOG

How To Call Lightning Web Component From Visualforce Page

  • October 27, 2023
  • Tech Blogger
  • Salesforce Developments Tutorial
  • 0

Introduction:

Calling a Lightning Web Component (LWC) from a Visual force page is a useful way to leverage the power and flexibility of Lightning components within your Salesforce Classic environment. Here’s a short description of how to achieve this:

1. Create a Lightning Web Component which will be shown on Visualforce Page.
2. Create a Lightning App so we can embed this component.
3. Create Visualforce Page where we show the lightning component.

ExampleLWC (Lightning Web Component):

<template>
<lightning-card title=”Lightning Web Component”>
<div class=”slds-p-horizontal_small”>
<p> The Component is call via Visualforce page. </p>
</div>
</lightning-card>
</template>
import { LightningElement, api } from ‘lwc’;
export default class ExampleLWC extends LightningElement {
}
}

ExampleLWCApp (Lightning Aura Application):
  • This is a Lightning Aura Application, which acts as a container for one or more
    Lightning components. It extends “ltng:outApp,” indicating that it’s designed for
    embedding Lightning components in external containers, such as Visualforce pages.
  • <aura:dependency resource=”ExampleLWC” /> specifies a dependency on the
    “ExampleLWC” Lightning Web Component, meaning that this app requires the
    “ExampleLWC” component to function properly.
<aura:application extends=”ltng:outApp” access=”GLOBAL” >
<aura:dependency resource=”ExampleLWC”/>
</aura:application>

ExampleVFpage (Visualforce page):
  • <apex:includeLightning /> includes the Lightning JavaScript library on the page. This
    is necessary for embedding Lightning components in Visualforce pages.
  • <div id=”lightning”></div> creates a placeholder <div> element with the id
    “lightning.” This is where the Lightning component will be rendered.
  • Inside the <script> tag, the $Lightning.use() function is called. This function loads the
    specified Lightning app and then creates the Lightning component inside the
    “lightning” div. The app being used is “c:ExampleLWCApp,” and it creates an
    instance of the “c:ExampleLWC” Lightning Web Component.

<apex:page standardController=”contact”>
<apex:includeLightning />
<div id=”lightning”> </div>
<script>
$Lightning.use(
“c:ExampleLWCApp”,
function() {
$Lightning.createComponent(
“c:ExampleLWC”,
{},
“lightning”
);
}
);

</script>
</apex:page>

Output :
 
Call lwc in vf page In Lightning View
Call lwc in vf page In Lightning View
Call lwc in vf page In Classic View
Call lwc in vf page In Classic View

Conclusion:

In summary, the code is setting up a Visual force page that loads a Lightning Aura
Application, which, in turn, depends on a Lightning Web Component. When the Visualforce
page is accessed, it will render the Lightning Web Component.

Related Blogs: https://merfantz.com/blog/aura-components-vs-lightning-web-components/

https://merfantz.com/blog/how_to_use_address_autocomplete_field_in_lwc_using_google_api/

Author Bio

Tech Blogger
+ Recent Posts
  • Let Einstein Help You Build - Salesforce Flow
    May 15, 2025
    Let Einstein Help You Build - Salesforce Flow
  • May 9, 2025
    Mastering Attachment Compression for Salesforce Developers
  • May 2, 2025
    Salesforce API Integrations: Connect with Slack, Zoom, and Teams
  • Guide to Streamlining Sales Success
    April 17, 2025
    Mastering Salesforce CPQ: A Comprehensive Guide to Streamlining Sales Success
Tags: Salesforce Development
  • Previous IMAGE COMPRESSION USING LIGHTNING WEB COMPONENT
  • Next How To Create Reactive Components in Salesforce Screen Flows
Merfantz Technologies is a leading Salesforce consulting firm dedicated to helping small and medium enterprises transform their operations and achieve their goals through the use of the Salesforce platform. Contact us today to learn more about our services and how we can help your business thrive.

Discover More

Terms and Conditions
Privacy Policy
Cancellation & Refund Policy

Contact Info

  • No 96, 2nd Floor, Greeta Tech Park, VSI Industrial Estate, Perungudi, Chennai 600 096, Tamil Nadu, INDIA
  • (+91) 44-49521562
  • [email protected]
  • 9:30 IST - 18:30 IST

Latest Posts

Let Einstein Help You Build - Salesforce Flow
Let Einstein Help You Build – Salesforce Flow May 15, 2025
Mastering Attachment Compression for Salesforce Developers May 9, 2025
Salesforce API Integrations: Connect with Slack, Zoom, and Teams May 2, 2025

Copyright @2023 Merfantz Technologies, All rights reserved