[SalesForce] Uncaught Error in $A.getCallback() [TypeError: Cannot read property ‘setParams’ of undefined

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

Best Answer

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