• 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
  • info@merfantz.com
  • (+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
  • How to Dynamically Evaluate Formulas in Salesforce Apex
    June 19, 2025
    How to Dynamically Evaluate Formulas in Salesforce Apex
  • Comprehensive Overview of Salesforce Agent-Force Platform
    June 12, 2025
    Comprehensive Overview of Salesforce Agent-Force Platform
  • Salesforce GraphQL Revolutionizing Data Queries in CRM
    June 6, 2025
    Salesforce GraphQL: Revolutionizing Data Queries in CRM
  • Unlocking the Power of Dynamic Forms in Salesforce Lightning App Builder
    May 29, 2025
    Unlocking the Power of Dynamic Forms in Salesforce Lightning App Builder
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
  • support@merfantz.com
  • 9:30 IST - 18:30 IST

Latest Posts

How to Dynamically Evaluate Formulas in Salesforce Apex
How to Dynamically Evaluate Formulas in Salesforce Apex June 19, 2025
Comprehensive Overview of Salesforce Agent-Force Platform
Comprehensive Overview of Salesforce Agent-Force Platform June 12, 2025
Salesforce GraphQL Revolutionizing Data Queries in CRM
Salesforce GraphQL: Revolutionizing Data Queries in CRM June 6, 2025

Copyright @2023 Merfantz Technologies, All rights reserved