Activity Forums Salesforce® Discussions Init() in salesforce

  • Anjali

    Member
    July 17, 2018 at 11:49 am

    Hello Madhulika,

    We use Init() event to initialize a component or fire an event after component construction but before Rendering.

    aura:init always runs first, as it runs the moment the component is constructed.

    In component source we use-

    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>

    Client side Controller source we use-

    doinit:function(component,event,helper)

     

  • shariq

    Member
    September 18, 2018 at 1:27 am

    Hi,

    This event is automatically fired when an app or component is initialized, prior to rendering.

    Component-

    <aura:component>

    <aura:handler name=”init” value=”{!this}” action=”{!c.doInit}”/>

    </aura:component>

    jsController-

    ({
    doInit: function(cmp) {
    // Set the attribute value.
    // You could also fire an event here instead.
    alert(‘test’);
    }
    })

    Hope this helps.

  • Parul

    Member
    September 18, 2018 at 2:50 am

    Hi.

    <aura:handler name=”init” value=”{!this}” action=”{!c.doInit}”/>

    This registers an init event handler for the component.

    init is a predefined event sent to every component.

    After the component is initialized, the doInit action is called in the component’s controller.
    In this sample, and the controller action sets an attribute value, but it could do something more interesting,
    such as firing an event.Setting value=”{!this}” marks this as a value event. You should always use this setting for an init event.

     

    THanks

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos