0

I am new to Salesforce development, so please excuse me if this is an obvious question.

I've developed a number of helper functions for my lightning component. For some of those functions, I need the component value in order to invoke an Apex function that is defined in my aura:component controller. Is there a way for me to look up the calling component that ultimately invoked the helper function or do I need to pass the component parameter down through the levels?

4
  • 1
    Hello Eric G, could you please clarify your question a bit more? I actually couldn't understand it. Do you mean passing data from Aura Component via JS to the Apex or something like that?
    – Mehedi
    Aug 12, 2021 at 17:58
  • You have to pass the component to the helper function.
    – CyberJus
    Aug 12, 2021 at 20:59
  • Thanks for confirming @CyberJus -- that's what it looked like (I need to pass the component). I just wanted to make sure I wasn't missing some way to find the component without passing it.
    – Eric G
    Aug 13, 2021 at 19:09
  • The helper is a singleton, there is just one instance of the helper for all of the components of that type, that is why it needs the component passed to it.
    – CyberJus
    Aug 18, 2021 at 21:03

1 Answer 1

0

controller.js

({
   doSth: function(component, event, helper) {
          helper.helperFunction(component, event, helper);
   }
})

helper.js

({
    helperFunction: function(component, event, helper) {
        // component  <-- this is your reference
    }
})
1
  • Thank you - that is what I am doing. I was hoping I didn't need to pass it in to all my helper functions, but I can continue to do that.
    – Eric G
    Aug 13, 2021 at 19:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .