Aura Action javascript object has setCallback function that we use to communicate with the server. The first parameter of the function is scope. Aura documentation has the following explanation:

Scope : Object

The scope in which the function is executed. You almost always want to set scope to the keyword this.

Experimenting with this keyword inside the component results in undefined when used inside controller.js and the helper object instance when used inside helper.js. Does someone know what the scope parameter is affecting? Using this feels wrong as it can be almost anything depending on the place in code the setCallback is executed from.

P.S. currently I have problems with private attribute visibility inside the action callback function so I am trying to eliminate all possible causes.

  • Yea you probably want setCallback(component, function(){});
    – Kris Gray
    Nov 30 '16 at 17:46
  • Can you post some info and source code relating to your private attribute visibility issue?
    – Kris Gray
    Nov 30 '16 at 17:47
  • I would post the issue with the private attribute in a separate post if I don't find a solution. I still need to experiment with it to eliminate all external factors. However, I would still like to know how scope affects the execution of the aura action. Why do you suggest to set the scope to component?
    – Artur
    Nov 30 '16 at 21:46
  • 1
    It only effects the this context of the client side callback. Nothing on the server is influenced.
    – Kris Gray
    Dec 1 '16 at 15:31
  • 1
    Right. So that first parameter just influences what is in the "this" context for your callback function. Are you having an access check issue?
    – Kris Gray
    Dec 1 '16 at 20:50

As @KrisGray pointed out in the comments - the scope affects this attribute inside the callback function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.