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
Raghu kattulaRaghu kattula 

This page has an error. You might just need to refresh it. Unable to find action 'Search' on the controller of c:LC_SearchAccount_v2 Failing descriptor: {c:LC_SearchAccount_v2}

Component



<aura:component controller="Class_Searchtext">
    
    <aura:attribute name="acc" type="Account[]" />
    <aura:attribute name="Search" type="String" />
    
  <lightning:card class="slds-m-around_medium" title="Accounts" iconName="standard:account">
       
       <aura:set attribute="actions">
            <lightning:buttonGroup>
            <lightning:button label="New" />
            <lightning:button label="Import" />
            <lightning:button label="Printable" />
            </lightning:buttonGroup>
       </aura:set>
      <div class="slds-m-around_medium">
          
      <lightning:layout>
          <lightning:layoutItem size="6">
     <lightning:input label="Enter name to search" value="{!v.Search}" />
          </lightning:layoutItem>
          
           <lightning:layoutItem size="6">
              
        <lightning:button label="Search" onclick="{!c.click}"  />
              </lightning:layoutItem>
          </lightning:layout>
          
          
          
         <lightning:layout multipleRows="true">
           
      <aura:iteration items="{!v.acc}" var="a">
          <lightning:layoutItem size="3" padding="around-small">
      Name:{!a.Name}
      Phone:{!a.Phone}
      Rating:{!a.Rating}
        </lightning:layoutItem>
          
          </aura:iteration>
          </lightning:layout>
      </div>
          
          
 </lightning:card>
</aura:component>


Apex class


public class Class_Searchtext
{
  @AuraEnabled
    Public Static List<Account> getaccount(String searchtext)
    {
        String query = 'select id,name,industry,phone,rating from Account where name like \'%'+searchtext+ '%\'';
        List<Account> accounts = Database.query(query);
        Return accounts;
    }
    
}


Controller



({
    click : function(component, event, helper)
    
    {
        var a= component.get("c.Search");
        var action = component.get("c.getaccount");
        
        action.setParams({"searchtext":a});
        action.setCallback(this,function(response){
            var st= response.getState();
            if(st=='SUCCESS')
            {
                var r = response.getReturnValue();
                alert('search results are ');
                component.set("v.acc",r);
            }
            
        });
                       
         $A.enqueueAction(action);                  
    }
})

Application


<aura:application extends="force:slds">
    <c:LC_SearchAccount_v2/>
    
</aura:application>
Best Answer chosen by Raghu kattula
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Raghu,

There was a small mistake in the controller. Can you please change it as below and check. Instead of 
component.get('v.Search');

you re using
var a= component.get("c.Search");

Can you make this change and check.
 
({
    click : function(component, event, helper)
    
    {
        var searchKey= component.get('v.Search');
       // var searchKey = component.find("searchKey").get("v.value");
        var action = component.get("c.getaccount");
        
        action.setParams({"searchtext":searchKey});
        action.setCallback(this,function(response){
            var st= response.getState();
            if(st=='SUCCESS')
            {
                var r = response.getReturnValue();
                alert('search results are ');
                component.set("v.acc",r);
            }
            
        });
                       
         $A.enqueueAction(action);                  
    }
})

If this solution helps, Please mark it as best answer.

Thanks,
 

All Answers

Sai PraveenSai Praveen (Salesforce Developers) 
Hi Raghu,

There was a small mistake in the controller. Can you please change it as below and check. Instead of 
component.get('v.Search');

you re using
var a= component.get("c.Search");

Can you make this change and check.
 
({
    click : function(component, event, helper)
    
    {
        var searchKey= component.get('v.Search');
       // var searchKey = component.find("searchKey").get("v.value");
        var action = component.get("c.getaccount");
        
        action.setParams({"searchtext":searchKey});
        action.setCallback(this,function(response){
            var st= response.getState();
            if(st=='SUCCESS')
            {
                var r = response.getReturnValue();
                alert('search results are ');
                component.set("v.acc",r);
            }
            
        });
                       
         $A.enqueueAction(action);                  
    }
})

If this solution helps, Please mark it as best answer.

Thanks,
 
This was selected as the best answer
Raghu kattulaRaghu kattula
Strugling from last night Thank you Sai Praveen its worked....