On every event I am passing the new siteID to the server side controller to get the list of the records, however I am getting the same list of records, no change. Event firing perfectly fine and also returning the correct siteId too. In the system each siteId has different set of records. Even I tried clearing the List using this "cmp.set("v.Interns", []);" but still same result.

Any suggestion?


<aura:handler event="c:FormSubmit" action="{!c.handleApplicationEvent}"/>

    <lightning:layout horizontalAlign="space" multipleRows="true">
        <aura:if isTrue="{!v.errorMessage}">
            <div class="slds-align_absolute-center">
                No Interns found
        <aura:iteration items="{!v.Interns}" var="int">
            <lightning:layoutItem flexibility="auto" size="12" mediumDeviceSize="6" 
                                  largeDeviceSize="3" padding="around-small">
                <c:InternshipTile intern="{!int}"/>


    /* aeHandlerController.js */
    handleApplicationEvent : function(cmp, event) {
        var message = event.getParam("siteId"); 
        var action = cmp.get("c.getInterns");

        action.setParam({"siteId": message});
        action.setCallback(this, function(response){
        var status = response.getState();
            if(status === "SUCCESS"){

             if(! $A.util.isEmpty(response.getReturnValue())){                   
                } else {
                     cmp.set("v.recordError","No boats found");


Firing Evevnt CMP:

<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    <aura:registerEvent name="siteIdEvent" type="c:FormSubmit"/>
    <aura:attribute name="State" type="String" default="All"/> <!-- Set default here because in this use case the initial value is passed into the component -->
    <aura:attribute name="siteOptions" access="public" type="String[]"/>    
    <lightning:layout horizontalAlign="center"   >        
        <lightning:layoutItem class="slds-grid_vertical-align-center" >            
            <lightning:select aura:id="typeSelect"
                <option value="">...Select a Site...</option>
                <aura:iteration items="{!v.siteOptions}" var="st">
                    <option value="{!st.label}" selected="{!st==v.state}">{!st.value}</option>
        <lightning:layoutItem class="slds-grid_vertical-align-center" > 
            <lightning:button label="Search" variant="brand" onclick='{!c.searchInt}' />



JS Controller:

searchInt : function(cmp, event) {

        var appEvent = $A.get("e.c:FormSubmit");
            "siteId" : cmp.find("typeSelect").get("v.value") 

Apex Class:

    public static list<Apprenticeship__c> getInterns(String siteId ) {
        List<Apprenticeship__c> interns=new List<Apprenticeship__c>();
        if(siteId != ''){
            interns = [SELECT Id,Name,Student_Contact__r.Picture__c,Student_Contact__r.FirstName,Student_Contact__r.LastName,Student__r.Name FROM Apprenticeship__c WHERE Site_Location__c=:siteId  LIMIT 5];
            interns = [SELECT Id,Name,Student_Contact__r.Picture__c,Student_Contact__r.FirstName,Student_Contact__r.LastName,Student__r.Name  FROM Apprenticeship__c LIMIT 30];

        return interns;

Screenshot: enter image description here

  • Can you show the code where the c:FormSubmit is being fired and the siteId attribute is being set?
    – Bob Lopez
    Jan 2 '18 at 22:54
  • Try putting system.debug(siteId); in your apex method, getInterns(). Then change the value of the drop down and click Search. Try with different picklist options and ensure you are seeing the expected value in your debug logs. Also check the options in v.siteOptions and make sure the label for each option is correct (not all the same).
    – Bob Lopez
    Jan 3 '18 at 1:18
  • siteId is coming as NULL in debug for some reason. USER_DEBUG [4]|DEBUG|*********siteId*** null. that is why it is going to else and returning all the records. why is the siteid not getting passed to the controller?
    – Ajay
    Jan 3 '18 at 4:08
  • Where is v.siteOptions being populated? Look at the code and make sure it is being populated correctly.
    – Bob Lopez
    Jan 3 '18 at 4:13
  • See here for more details on how to properly get/set the values of the picklist component: developer.salesforce.com/docs/atlas.en-us.lightning.meta/…
    – Bob Lopez
    Jan 3 '18 at 4:16

It looks like you are not setting the server side controller parameter correctly. This is why you see the value in your JS controller, but it is showing null in your apex controller.

Change this:

action.setParam({"siteId": message});

To this (syntax for array of params):

action.setParams({"siteId": message});

Looks like you are just missing the s at the end of setParams()

I believe you can also set a single param using this syntax:

action.setParam("siteId", message);
  • As mentioned earlier, su
    – Ajay
    Jan 2 '18 at 22:36
  • Siteid is being set correctly I am also printi g it as you can see the screenshot, but for some reason not passing to controller and get the new list of records
    – Ajay
    Jan 2 '18 at 22:39
  • Oh I see, you are not trying to get the Salesforce Site Id. You are trying to get the selected picklist option on click of Search and render related Internships. Please include more information on how the siteId is being set and I will update my answer
    – Bob Lopez
    Jan 2 '18 at 22:56
  • Yes, Updated the description with Firing Event CMP and it's JS controller.
    – Ajay
    Jan 3 '18 at 0:15
  • Can you also include the code for your apex controller method getInterns()
    – Bob Lopez
    Jan 3 '18 at 0:44

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.