function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sree SalesforceSree Salesforce 

searchkeyword value is not passing (action.setParam) to apex. I am not getting the result. Could please check the below code.

Component:-
<aura:component controller="searchAccountController">
   <ltng:require styles="{! $Resource.SLDS24+ '/assets/styles/salesforce-lightning-design-system.css'}"/>
    <aura:attribute name="searchResult" type="List" description="use for store and display account list return from server"/>
   <aura:attribute name="searchKeyword" description="use for input" type="string" ></aura:attribute>
    <aura:attribute name="Message" type="boolean" default="false" description="use for display no record found message"/>
    <div class="slds-m-around--large">
       <form class="slds-form--inline"> 
         <div class="slds-form-element"> 
            <label class="slds-form-element__label" for="Search">Account Search</label>  
              <div class="slds-form-element__control" >
                <ui:inputtext aura:id="searchId" value="{!v.searchKeyword}" placeholder="Type Account Name" required="true" class="slds-input"></ui:inputtext>
              </div>
            </div> 
             <div class="slds-form-element">
                 <button type="Button" onclick="{!c.Search}" class="slds-button slds-button--brand">Search</button>
                 </div>
        </form>   
        <table class="slds-table slds-table--bordered slds-table--cell-buffer">
            <thead>
                <tr class="slds-text-title--caps">
                    <th scope="col">
                         <div class="slds-truncate" title=" Name"> ID</div>
                    </th>
                    <th scope="col">
                         <div class="slds-truncate" title=" Name"> Name</div>
                    </th>   
                     <th scope="col">
                          <div class="slds-truncate" title="Type">Type</div>
                       </th>
                       <th scope="col">
                          <div class="slds-truncate" title="Industry">Industry</div>
                       </th>
                       <th scope="col">
                          <div class="slds-truncate" title="Phone">Phone</div>
                       </th>
                       <th scope="col">
                          <div class="slds-truncate" title="Fax">Fax</div>
                       </th>
                </tr>
            </thead>
            <tbody>
            <aura:if isTrue="{!v.Message}">
               <div class="slds-text-color--error"> No Result Found...</div>
            </aura:if>
                <aura:iteration items="{!v.searchResult}" var="acc"> 
              <tr>
                  <td>
                     <div class="slds-truncate">{!acc.Id}</div>
                  </td>
                   <td>
                     <div class="slds-truncate">{!acc.name}</div>
                  </td>
                  <td>
                     <div class="slds-truncate">{!acc.Type}</div>
                  </td>
                  <td>
                     <div class="slds-truncate">{!acc.industry}</div>
                  </td>
                    <td>
                     <div class="slds-truncate">{!acc.Phone}</div>
                  </td>
                    <td>
                     <div class="slds-truncate">{!acc.fax}</div>
                  </td>
              </tr>
                </aura:iteration>    
            </tbody>
        </table>
      </div>     
     
</aura:component>

JS Controller :- 

({
    Search : function(component, event, helper) {
        var searchKeyId=component.find("searchId"); 
        var searchKey=component.get('v.searchKeyword');
        alert('==searchKeyword'+searchKey);
        if(searchKey == '' || searchKey == null)
        {
            alert('enter');
            searchKeyId.set("v.errors",[{message: "Enter search Keyword" }]);
        }
        else{
            helper.searchHelper(component,event);
        } 
    },
})

Helper :- 
({
    searchHelper: function(component, event) {
        var action = component.get("c.search");
        alert('====key'+component.get("v.searchKeyword"));
        action.setParams({
            'searchKeyWord': component.get("v.searchKeyword")         
        });
        action.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
                var storeResponse = response.getReturnValue();
                // if storeResponse size is 0 ,display no record found message on screen.
                if (storeResponse.length == 0) {
                    component.set("v.Message", true);
                } else {
                    component.set("v.Message", false);
                
                }
                // set numberOfRecord attribute value with length of return value from server
                //component.set("v.numberOfRecord", storeResponse.length);
                // set searchResult list with return value from server.
                  component.set("v.searchResult", storeResponse);
                    alert('==='+component.set("v.searchResult", storeResponse));
            } 
 
        });
        $A.enqueueAction(action);
 
    },
})

Apex:-
public class searchAccountController {

 @AuraEnabled
  public static list<account> search(string searchKeyword)
  {
    system.debug('--enter --'+searchKeyWord);
    String searchKey=searchKeyword + '%';
    system.debug('--enter =--'+searchKey);
    list<account> returnList =new list<account>();
    list<account> AccList=[select id,name,type,industry,phone,fax from account where name like: searchKey ];
    for(account acc:AccList)
    {
    returnList.add(acc);
    system.debug('--ret list-'+returnList);
    }
    return returnList;
    
  }
}
Best Answer chosen by Sree Salesforce
sfdcMonkey.comsfdcMonkey.com
hi sri manne 
your code is not working because -:
1. you are using search keyword for method name on your apex code don't choose comman names or reserve keywords
so first change your method name also update it in your helper code where you are using
var action = component.get("c.search");
2. in your apex class search method you are using string searchKeyword parameter but in your js helper code you useing 
   'searchKeyWord': component.get("v.searchKeyword")      

here java Script is case sensetive so searchKeyWord and searchKeyword  are two different words 
correct above error and your code work perfectly
thanks
let me infrom if it helps you and mark it best answer if it helps you so it make proper solutions for others
http://sfdcmonkey.com