Close Menu
SalesforceCodex
    Facebook X (Twitter) Instagram
    Trending
    • How to Build a Generic Modal Window in Lightning Web Component
    • Top 10 Salesforce Flow Features of Salesforce Summer ’25
    • Unlock the Power of Vibe Coding in Salesforce
    • How to Implement Dynamic Queueable Chaining in Salesforce Apex
    • How to Implement Basic Queueable Chaining in Salesforce Apex
    • How to Suppress PMD Warnings in Salesforce Apex
    • Top 10 PMD Issues Salesforce Developers Should Focus on in Apex
    • How to Use Graph API for Outlook-Salesforce Connection
    Facebook X (Twitter) Instagram
    SalesforceCodex
    Subscribe
    Friday, May 30
    • Home
    • Architecture
    • Salesforce
      • News
      • Apex
      • Integration
      • Books Testimonial
    • Questions
    • Certification
      • How to Prepare for Salesforce Integration Architect Exam
      • Certification Coupons
    • Integration Posts
    • Downloads
    • About Us
      • Privacy Policy
    SalesforceCodex
    Home»Salesforce»Apex»Dynamic Interaction Between Two LWCs

    Dynamic Interaction Between Two LWCs

    Dhanik Lal SahniBy Dhanik Lal SahniApril 30, 2022Updated:June 11, 20233 Comments3 Mins Read
    Facebook Twitter Pinterest LinkedIn Tumblr Email
    Dynamic Interaction Between Two LWCs
    Share
    Facebook Twitter LinkedIn Pinterest Email

    Many times we have requirements to update or show detail on other components based on the action of the first component. Like we can have one component which will show a list of accounts and on selection, we will show the address of that account on a map. This post will explain to create a dynamic interaction between two LWCs.

    To accomplish the above requirement we can have the below solutions

    1. Use events interaction
    2. Use Method handler
    3. Use Dynamic Interaction

    The top two approaches are completely code-based and tightly coupled with each other. The last approach (dynamic interaction) is a combination of custom development and admin configuration. We will focus on the last approach in this post. Before starting the code logic, let us see what is dynamic interaction.

    Dynamic Interactions are a new way to interact with each other within same app page. An event occurring in one component on a Lightning page can update other components on the page.

    Dynamic Interactions has four important building blocks.

    • Event—Anything that can trigger an interaction, such as a save button click or a change in a picklist value.
    • Interaction—An activity that happens between the source and the target. Basically what interaction we are doing between components.
    • Source—The item triggering the event. It can be Lightning web components or Dynamic Actions Bar components.
    • Target—The item that’s the target of the interaction. Any component on a Lightning page can be a target.

    Let us implement logic to handle our business requirements.

    1. Source Component:

    First component is the account list component which will show all accounts. It will also create an event that will propagate the event to the second component for action.

    Apex Class:

    LWC:

    Let us create a source LWC component. We are using lightning-datatable component to show the list of accounts. On record selection itemselected event is fired using datatable row selection event.

    Apex Class AccountSelector is used to retrieve accounts.

    Dynamic Interaction Creation:

    As this LWC is a source component, we have to create events and properties which need to send to the second component. File accountSelector.js-meta.xml targetConfig has event and property definition. We will see the configuration last when we test it.

    2. Target Component

    Let us create a target LWC component that will show the address on the map for the selected record from the source component. We are using recordid property to get address information for that account and this address information is shown on lightning-map component.

    Apex Class:

    Above created apex class will be used for this component as well.

    LWC:

    Configuration Properties:

    Create properties for setting recordId from dynamic interaction.

    Test Dynamic Interaction:

    Let us test dynamic interaction by configuring it on the lightning app builder page.

    Create one lightning app builder page or use any existing app builder page. I have created a page with two sections. One section is containing the source component (accountSelector) and a second section shows the target component (accountAddress).

    Dynamic Interaction Configuration- SalesforceCodex

    To configure dynamic interaction, select accountSelector and click on interactions on the right side.

    Create new interaction similar to the below image. if we have a single event and properties by default Event and Interaction will be selected. Select target component from component picklist and in Record Id properties set value {!Event.recordId}, recordId (Record Id) is public properties created in target component.

    Dynamic Interaction Configuration- SalesforceCodex

    Demo:

    Related Post:

    Communicate Across Salesforce UI Technologies with Lightning Message Service

    Generic DataTable in Lightning Web Component

    References:

    Introducing Dynamic Interactions, the Latest Low-Code Innovation for Salesforce Platform

    Configure a Component for Dynamic Interactions in the Lightning App Builder

    component interaction dynamic datatable dynamic interaction event propagation lightning lightning component lightning map Lightning web component lightning-datatable lightning-map lwc
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Previous ArticleAWS Signature 4 Signing in Salesforce
    Next Article Custom Toast with custom duration In LWC
    Dhanik Lal Sahni
    • Website
    • Facebook
    • X (Twitter)

    With over 18 years of experience in web-based application development, I specialize in Salesforce technology and its ecosystem. My journey has equipped me with expertise in a diverse range of technologies including .NET, .NET Core, MS Dynamics CRM, Azure, Oracle, and SQL Server. I am dedicated to staying at the forefront of technological advancements and continuously researching new developments in the Salesforce realm. My focus remains on leveraging technology to create innovative solutions that drive business success.

    Related Posts

    By Dhanik Lal Sahni4 Mins Read

    How to Build a Generic Modal Window in Lightning Web Component

    May 26, 2025
    By Dhanik Lal Sahni6 Mins Read

    Top 10 Salesforce Flow Features of Salesforce Summer ’25

    May 11, 2025
    By Dhanik Lal Sahni6 Mins Read

    Unlock the Power of Vibe Coding in Salesforce

    April 30, 2025
    View 3 Comments

    3 Comments

    1. Pingback: 20 Most Popular Salesforce Admin & Developer Blogs 2022 | Salesforce Ben

    2. Pingback: Integrate Google reCaptcha v3 into the Salesforce Sites

    3. Pingback: How to Export Data in Excel with SheetJS in LWC

    Leave A Reply Cancel Reply

    Ranked #1 SALESFORCE DEVELOPER BLOG BY SALESFORCEBEN.COM
    Featured on Top Salesforce Developer Blog By ApexHours
    Recent Posts
    • How to Build a Generic Modal Window in Lightning Web Component
    • Top 10 Salesforce Flow Features of Salesforce Summer ’25
    • Unlock the Power of Vibe Coding in Salesforce
    • How to Implement Dynamic Queueable Chaining in Salesforce Apex
    • How to Implement Basic Queueable Chaining in Salesforce Apex
    Ranked in Top Salesforce Blog by feedspot.com
    RSS Recent Stories
    • How to Connect Excel to Salesforce to Manage Your Data and Metadata February 9, 2025
    • Difference Between With Security and Without Security in Apex January 2, 2025
    • Top Reasons to Love Salesforce Trailhead: A Comprehensive Guide December 5, 2024
    • How to Utilize Apex Properties in Salesforce November 3, 2024
    • How to Choose Between SOQL and SOSL Queries July 31, 2024
    Archives
    Categories
    Tags
    apex (111) apex code best practice (8) apex rest (11) apex trigger best practices (4) architecture (22) Asynchronous apex (9) AWS (5) batch apex (9) batch processing (4) code optimization (8) code review tools (3) custom metadata types (5) design principle (9) file upload (3) flow (15) future method (4) google (6) google api (4) integration (19) integration architecture (6) lighting (8) lightning (64) lightning-combobox (5) lightning-datatable (10) lightning component (30) Lightning web component (62) lwc (51) named credential (8) news (4) optimize apex code (4) Permission set (4) pmd (3) Queueable (9) rest api (23) S3 Server (4) salesforce (141) salesforce apex (46) salesforce api (4) salesforce api integration (5) Salesforce Interview Question (4) salesforce news (5) salesforce question (5) solid (6) tooling api (5) Winter 20 (8)

    Get our newsletter

    Want the latest from our blog straight to your inbox? Chucks us your detail and get mail when new post is published.
    * indicates required

    Ranked #1 SALESFORCE DEVELOPER BLOG BY SALESFORCEBEN.COM
    Featured on Top Salesforce Developer Blog By ApexHours
    Recent Posts
    • How to Build a Generic Modal Window in Lightning Web Component
    • Top 10 Salesforce Flow Features of Salesforce Summer ’25
    • Unlock the Power of Vibe Coding in Salesforce
    • How to Implement Dynamic Queueable Chaining in Salesforce Apex
    • How to Implement Basic Queueable Chaining in Salesforce Apex
    Ranked in Top Salesforce Blog by feedspot.com
    RSS Recent Stories
    • How to Connect Excel to Salesforce to Manage Your Data and Metadata February 9, 2025
    • Difference Between With Security and Without Security in Apex January 2, 2025
    • Top Reasons to Love Salesforce Trailhead: A Comprehensive Guide December 5, 2024
    • How to Utilize Apex Properties in Salesforce November 3, 2024
    • How to Choose Between SOQL and SOSL Queries July 31, 2024
    Archives
    Categories
    Tags
    apex (111) apex code best practice (8) apex rest (11) apex trigger best practices (4) architecture (22) Asynchronous apex (9) AWS (5) batch apex (9) batch processing (4) code optimization (8) code review tools (3) custom metadata types (5) design principle (9) file upload (3) flow (15) future method (4) google (6) google api (4) integration (19) integration architecture (6) lighting (8) lightning (64) lightning-combobox (5) lightning-datatable (10) lightning component (30) Lightning web component (62) lwc (51) named credential (8) news (4) optimize apex code (4) Permission set (4) pmd (3) Queueable (9) rest api (23) S3 Server (4) salesforce (141) salesforce apex (46) salesforce api (4) salesforce api integration (5) Salesforce Interview Question (4) salesforce news (5) salesforce question (5) solid (6) tooling api (5) Winter 20 (8)

    Get our newsletter

    Want the latest from our blog straight to your inbox? Chucks us your detail and get mail when new post is published.
    * indicates required

    Facebook X (Twitter) Instagram Pinterest YouTube Tumblr LinkedIn Reddit Telegram
    © 2025 SalesforceCodex.com. Designed by Vagmine Cloud Solution.

    Type above and press Enter to search. Press Esc to cancel.

    Ad Blocker Enabled!
    Ad Blocker Enabled!
    Our website is made possible by displaying online advertisements to our visitors. Please support us by disabling your Ad Blocker.