In a lightning component I call an apex method, like that :

for(var cmp in component.find("inQuantity")){
  var CallMethod = component.get("c.calculate")[cmp]; 
  var product = component.get("v.product")[cmp];
    "prod" : JSON.stringify(product)
  vCalcMethod.setCallback(pComponent, function(pResponse) {
    //some code

The apex method need a string in parameter, I try to pass it through the setParams. But at this point I got an error in javascript :

Cannot read property 'setParams' of undefined

But when I put a debug console.log('product to string' + JSON.stringify(product )); I got the object into a string, like I want, it is not "undefined".

  • Here it's your CallMethod variable that is undefined, not product. Dec 5, 2016 at 16:54

1 Answer 1


Your CallMethod variable is undefined. Try changing:

var CallMethod = component.get("c.calculate")[cmp];


var CallMethod = component.get("c.calculate");

and make sure you've defined an action called calculate that's accessible on your component.

You must log in to answer this question.

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