• #30191
    Forcetalks

    What are the types of custom events in Salesforce Lightning condition?

    What are the types of custom events in Salesforce Lightning condition? Explain all the types in detail.

     

    #30770
     Prachi #6
    Forcetalks

    Hello shradha,

    Types of custom events:-

    Component-Level Events
    Component-level events are generated by a component and can be handled by the component itself, or its containing component or application. Component events are useful for situations where your component can be used in an application multiple times and you don’t want the different instances interfering with each other.

    Application-Level Events
    Application-level events are published by a component, and any component or application that has subscribed to the event has its handler invoked when the event is fired.

    Thanks.

    #35143
    Salesforce | shariq shariq #1
    Forcetalks

    Hi,

    Here is the example –

    Componenet level event

    <aura:event type=”COMPONENT” description=”Fired when a Contact search is completed”>
    <aura:attribute name=”contacts” type=”Contact[]” description=”The result of the search, which could be an empty array”/>
    </aura:event>

    Application level event

    <!–c:aeEvent–>
    <aura:event type=”APPLICATION”>
    <aura:attribute name=”message” type=”String”/>
    </aura:event>

    Hope this helps.

    #35215
    Salesforce | Parul Parul #2
    Forcetalks

    All we know, that we have 2 types of Events

    Application Event: Application events follow a traditional publish-subscribe model. An application event is fired from an instance of a component. All components that provide a handler for the event are notified.

    <!–c:aeEvent–>
    <aura:event type=”APPLICATION”>
    <aura:attribute name=”message” type=”String”/>
    </aura:event>
    Component Event: A component event is fired from an instance of a component. A component event can be handled by the component that fired the event or by a component in the containment hierarchy that receives the event.

    <!–c:ceEvent–>
    <aura:event type=”COMPONENT”>
    <aura:attribute name=”message” type=”String”/>
    </aura:event>
    All components inside the Application will get notified when Application event fires. where as Component event only those component will notify which are in hierarchy.

    Thanks

    #41784
    Forcetalks

    Hello shradha,

    Types of custom events:-

    Component-Level Events
    Component-level events are generated by a component and can be handled by the component itself, or its containing component or application.

    <!–c:ceEvent–>
    <aura:event type=”COMPONENT”>
    <aura:attribute name=”message” type=”String”/>
    </aura:event>

    Application-Level Events
    Application-level events are published by a component, and any component or application that has subscribed to the event has its handler invoked when the event is fired.

    <!–c:aeEvent–>
    <aura:event type=”APPLICATION”>
    <aura:attribute name=”message” type=”String”/>
    </aura:event>

    Thanks.

    #52589
    Salesforce | Jade Jade #10
    Forcetalks

    Hello Shradha,

    Basically there are two types of Events as everyone answered –

    Let me tell you the basic difference and when to choose what –

    COMPONENT EVENT : It only works if one component is in Parent-child relationship with other component.

    In Other words-  To talk to a parent using the capture and bubbling mechanism, like with DOM events. Usually, one component is interested by the event, like an event aggregator.

    Component must reference events by name, much like an aura:id, and retrieve them from its component (hence component.get()) value provider:

    var evt = cmp.get(“e.myEvent”);

    You would then declare myEvent on the component as:

    <aura:registerEvent name=”myEvent” type=”namespace:eventName”/>

    Declaring events on a component allows other components to call controller methods. You had to declare a handler:

    <aura:handler name=”myEvent” action=”{!c.myEventHandler}”/>

    That allowed you to call myEventHandler from another component and respect the interface:

    component.get(“e.myEvent”).fire();

    For Example refer this Link : https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/events_component_example.htm

    APPLICATION EVENT : This will help you in communication between components which are not necessarily related.

    In other words :

    To broadcast to other components and not exclusively ancestors. Applications events can talk to many components that can be interested by the event. The broadcast can be boxed to an area of the DOM (everything below a DIV for example).

    This is obtained from the global (hence $A.get()) event value provider:

    var evt = $A.get(“e.myNamespace:myEvent”);

    For Example Refer this link : https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/events_application_example.htm

    Hope this will help.

    Thanks

     

    • This reply was modified 2 months ago by Salesforce | Jade Jade.
Viewing 6 posts - 1 through 6 (of 6 total)

Please to reply to this topic.

CONTACT US

We're not around right now. But you can send us an email and we'll get back to you, asap.

Sending

About Us

Forcetalks is a Salesforce collaboration platform for coders & developers, geeks & nerds, consultants & business heads, admins & architects, managers & marketers and of course the business owners. A community where you can learn from, where you can contribute to. For you. For Salesforce. Read More...

Copyright 2019 Forcetalks. All Right Reserved.

Log in with your credentials

or    

Forgot your details?