+ Start a Discussion
badri nath 9badri nath 9 

didnt getting response check me once?

component:
<aura:component  implements="force:appHostable"  controller = "SearchClass">
    <aura:attribute name = "search" type = "string" />
    <aura:attribute name = "accnts" type ="Account[]" />
    <ui:inputText value = "{!v.search}" class = "slds-input" placeholder = "Account Search"/>
    <lightning:button onclick = "{!c.search}"  name = "btn1" label = "Search"/>
    <aura:iteration items = "{!v.accnts}" var = "a" >
        <ui:outputText value = "{!a.Id}" />
        <ui:outputText value = "{!a.Type}" />
    </aura:iteration>
</aura:component>
controller:
({
    search : function(component, event, helper) {
        var action = component.get("c.getAccounts");
        var value1 = component.get("v.search");
        //alert(value1);
          action.setParam({ "acc"  : value1 });
                action.setCallback(this, function(response) {
            var state = response.getState();

            if (state === "SUCCESS") {
        component.set("v.accnts" ,response.getReturnValue());

                alert("From server: " + response.getReturnValue());
            }
    });
        $A.enqueueAction(action);

 }
})

serversidecontroller:
public class SearchClass {
   @AuraEnabled
    public static List<Account> getAccounts(string acc){
         string accname ;
            accname = acc ;
        list<account> actlst = new list<Account>();
         actlst = [select Id ,Type from Account where Name = 'accname' ];
        return actlst;
    } 
    
    
Best Answer chosen by badri nath 9
GauravGargGauravGarg
hi Badri,

There are two mistake in your code:
  1. First: setParams currently you are using setParam
  2. Secondly: In Apex controller use ":" semicolon notation to populate field. Please use below code:
  3. public class SearchController {
       @AuraEnabled
        public static List<Account> getAccounts(string acc){
             list<account> actlst = new list<Account>();
             actlst = [select Id ,Type from Account where Name = :acc ];
            system.debug(actlst);
            return actlst;
        } 
        
        
    }
Hope this helps!!!

Thanks,
Gaurav
Skype: gaurav62990

All Answers

GauravGargGauravGarg
hi Badri,

There are two mistake in your code:
  1. First: setParams currently you are using setParam
  2. Secondly: In Apex controller use ":" semicolon notation to populate field. Please use below code:
  3. public class SearchController {
       @AuraEnabled
        public static List<Account> getAccounts(string acc){
             list<account> actlst = new list<Account>();
             actlst = [select Id ,Type from Account where Name = :acc ];
            system.debug(actlst);
            return actlst;
        } 
        
        
    }
Hope this helps!!!

Thanks,
Gaurav
Skype: gaurav62990
This was selected as the best answer
badri nath 9badri nath 9
Thank you Gaurav