Activity Forums Salesforce® Discussions How can we call child component controller method from parent component controller method in Salesforce?

  • shariq

    Member
    September 23, 2018 at 10:46 pm

    To call a child component’s controller method, we need to first create a aura:method which is publically accessible, aura:method is used to communicate down the containment hierarchy i.e. parent to child. Sample code for implementing the aura method:
    Component code

    Controller
    ({
    publicmethod: function(cmp, event) {
    var params = event.getParam(‘arguments’);
    if (params) {
    var message = params. str;
    console.log(“message: ” + message);
    return message;
    }
    }
    })

    Calling the cild method from parent controller
    ({
    callchildCompMethod : function(component, event, helper) {
    var childCmp = component.find(“childCompName”);
    var Result =
    childCmp. publicmethod (“message sent by parent component”);
    console.log(“Result: ” + Result);
    }
    })

  • Parul

    Member
    September 24, 2018 at 1:29 am

    aura:method which is publically accessible, aura:method is used to communicate down the containment hierarchy i.e. parent to child.

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos