You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In this post we are going to learn about How to Use Application Event to pass attribute value from one lightning component to another in aura lightning component Salesforce.
Event-driven programming is used in many languages and frameworks, such as JavaScript and Java Swing. The idea is that you write handlers that respond to interface events as they occur.
A component registers that it may fire an event in its markup. Events are fired from JavaScript controller actions that are typically triggered by a user interacting with the user interface.
There are two types of events in the framework:
Component events are handled by the component itself or a component that instantiates or contains the component.
Application events are handled by all components that are listening to the event. These events are essentially a traditional publish-subscribe model. To know more details about Events, Clcick Here.
Create Apex Class Controller
Step 8:- Create Apex Class : accountEventCtrl.apxc
` public class accountEventCtrl {
@AuraEnabled
public static List accItemList( Id recId){
List accObj = [SELECT Id, Name, Phone, Industry, TYPE, Description FROM Account WHERE Id=:recId];
system.debug('accObj ' + accObj);
RETURN accObj;
}
In this post we are going to learn about How to Use Application Event to pass attribute value from one lightning component to another in aura lightning component Salesforce.
Event-driven programming is used in many languages and frameworks, such as JavaScript and Java Swing. The idea is that you write handlers that respond to interface events as they occur.
A component registers that it may fire an event in its markup. Events are fired from JavaScript controller actions that are typically triggered by a user interacting with the user interface.
There are two types of events in the framework:
Component events are handled by the component itself or a component that instantiates or contains the component.
Application events are handled by all components that are listening to the event. These events are essentially a traditional publish-subscribe model. To know more details about Events, Clcick Here.
👉 To get source code live demo link, Click Here.
Create Lightning Component
Step 1:- Create Lightning Component : appEventCmp.cmp
`<aura:component controller="accountEventCtrl" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global">
<aura:registerEvent name="regAppEvent" type="c:myAppEvent"/>
<aura:attribute name="isLoading" type="Boolean" default="false"/>
<aura:attribute name="showAccDetails" type="boolean"/>
</aura:component>`
Create JavaScript Controller
Step 2:- Create Lightning Component : appEventCmpController.js
` ({
findAccDetail : function(component, event, helper) {
helper.recordAccData(component, event, helper);
},
})`
Create JavaScript Helper
Step 3:- Create Lightning Component : appEventCmpHelper.js
({
})`
Create Lightning Component
Step 4:- Create Lightning Component : AccountDetailsCmp.cmp
`<aura:component controller="accountEventCtrl" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global">
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
<aura:attribute name="accListItem" type="List"/>
<aura:handler event="c:myAppEvent" action="{!c.storeEventData}"/>
<aura:attribute name="accID" type="string"/>
</aura:component>`
Create JavaScript Controller
Step 5:- Create Lightning Component : AccountDetailsCmpController.js
` ({
doInit : function(component, event, helper) {
},
})`
Create JavaScript Helper
Step 6:- Create Lightning Component : AccountDetailsCmpHelper.js
`({
storeEventDataHelper : function(component, event, helper) {
var accItemEvntData = event.getParam("accItemEvntData");
var accID = event.getParam("accID");
})`
Create Lightning Event
Step 7:- Create Lightning Event : myAppEvent.evt
<aura:event type="APPLICATION" description="Event template"> <aura:attribute name="accItemEvntData" type="accountEventCtrl[]"/> <aura:attribute name="accID" type="String"/> </aura:event>
Create Apex Class Controller
Step 8:- Create Apex Class : accountEventCtrl.apxc
` public class accountEventCtrl {
@AuraEnabled
public static List accItemList( Id recId){
List accObj = [SELECT Id, Name, Phone, Industry, TYPE, Description FROM Account WHERE Id=:recId];
system.debug('accObj ' + accObj);
RETURN accObj;
}
}`
👉 To get source code live demo link, Click Here.
The text was updated successfully, but these errors were encountered: