2
Uncaught Error in $A.getCallback() [TypeError: Cannot read property 'setParams' of undefined]
throws at https://growerslightning-dev-ed.lightning.force.com/auraFW/javascript/BC4wqH7bmsI7etc2sB4tmQ/aura_prod.js:1:27
    at Object.eval (eval at Nx (https://growerslightning-dev-ed.lightning.force.com/auraFW/javascript/BC4wqH7bmsI7etc2sB4tmQ/aura_prod.js:102:341), <anonymous>:52:23)
    at Object.<anonymous> (https://growerslightning-dev-ed.lightning.force.com/auraFW/javascript/BC4wqH7bmsI7etc2sB4tmQ/aura_prod.js:516:140)
    at G.kb (https://growerslightning-dev-ed.lightning.force.com/auraFW/javascript/BC4wqH7bmsI7etc2sB4tmQ/aura_prod.js:279:333)
    at WC.z.lj (https://growerslightning-dev-ed.lightning.force.com/auraFW/javascript/BC4wqH7bmsI7etc2sB4tmQ/aura_prod.js:567:295)
    at Object.Ky.lh (https://growerslightning-dev-ed.lightning.force.com/auraFW/javascript/BC4wqH7bmsI7etc2sB4tmQ/aura_prod.js:152:255)
    at G.kb (https://growerslightning-dev-ed.lightning.force.com/auraFW/javascript/BC4wqH7bmsI7etc2sB4tmQ/aura_prod.js:151:130)
    at zA (https://growerslightning-dev-ed.lightning.force.com/auraFW/javascript/BC4wqH7bmsI7etc2sB4tmQ/aura_prod.js:321:79)
    at AuraClientService.z.eg (https://growerslightning-dev-ed.lightning.force.com/auraFW/javascript/BC4wqH7bmsI7etc2sB4tmQ/aura_prod.js:351:149)
    at Object.Tk (https://growerslightning-dev-ed.lightning.force.com/auraFW/javascript/BC4wqH7bmsI7etc2sB4tmQ/aura_prod.js:564:388)
    at Object.Ky.lh (https://growerslightning-dev-ed.lightning.force.com/auraFW/javascript/BC4wqH7bmsI7etc2sB4tmQ/aura_prod.js:152:255)

I got this error when i click on my component tab. I create a component which code is this

<aura:component controller="Requisition" implements="force:appHostable">
        <ltng:require scripts="/resource/jquery" />


     <link href='/resource/Styles/css/custom.css' rel="stylesheet"/>
     <aura:attribute name="source" type="SourceRequisition__c" Access="global"/>
      <aura:attribute name="Id" type="SourceRequisition__c"  access="global"/>`div class="col-sm-6">
                                    <div class="col-xs-12">
                                        <div class="form-group label-floating">
                                            <label for="suppliername">Find</label>
                                            <input type="text" aura:id="Test2" class="form-control" placeholder="Requisition Title" value="" />

    </div>
 <div class="pull-left ml10">
      <button type="submit" class="btn btn-primary" onclick="{!c.serach}">Search</button>                                              

    </div>
 </aura:component>

My helper code isthis

({ 
    loadSupplier : function(component) { debugger; 
        // var searchKey = event.getParam("SupllierName");
        var action = component.get("c.findAll"); 

        action.setParams({            
            "SupllierName":component.find("Test2").get("v.value")||'',

         });
        action.setCallback(this, function(a) { debugger;
            if (a.getState()== "SUCCESS") { debugger;
                var v=a.getReturnValue();  
                //debugger;
                component.set("v.source", a.getReturnValue());
                var myEvent = $A.get("e.c:SearchKeyChangeLightning");
               myEvent.setParams({"source": a.getReturnValue()});
               myEvent.fire();
            }  else if (a.getState() == "ERROR") {
                $A.log("Errors", a.getError());
            }  
        });

        $A.enqueueAction(action);
    } 



})

Here is my servercontroller code:

@AuraEnabled
  public  static  List<SourceRequisition__c>findAll(string SupllierName)
   {
       String usrid = UserInfo.getUserId() ;  
 String queryString ='select id,Name,Title__c from SourceRequisition__c where Active__c =\'Yes\'';
 if(SupllierName!=null && !SupllierName.equals('')){

    queryString += ' AND Title__c LIKE \'%' + String.escapeSingleQuotes(SupllierName) +  '%\'';
 }
 transient List<SourceRequisition__c> ss= database.Query(queryString);
  return ss;

 }

I got this error.I didn't got my value on helper.please help me where i am wrong

1
  • Not quite sure. But i guess the issue is that your attribute type is a single element. And you are trying to assign a List to it. Change the attribute type to List and check if you are getting the error. Commented Jun 30, 2016 at 12:14

2 Answers 2

4

The problem seems to be happening with

myEvent.setParams

Because myEvent is undefined, to fire an event you first need to define it, if you think to fire the event from this component, you must to 'register' the event, and to define the event 'handler' where you want.

For more info, check the online help: https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/events_demo.htm

1

The error message is a bit convoluted because of Aura's internal workings but I think the exception is thrown in the second of these two lines:

var myEvent = $A.get("e.c:SearchKeyChangeLightning");
myEvent.setParams({"source": a.getReturnValue()});

The message implies that myEvent is undefined, and thus it throws an exception when you try and execute .setParams from it. So that means your $A.get call returned undefined: It cannot find the event you are searching for. Are you sure the spelling matches exactly? Do you have any trouble running the same two lines of code outside an action.setCallback?

You must log in to answer this question.

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