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
sakthidharan Ambayiramsakthidharan Ambayiram 

getting the below error for the component when i try fetch the filter accounts

Hi all,

Error: This page has an error. You might just need to refresh it.
Error in $A.getCallback() [response.getReturnValue is not a function]
Callback failed: apex://getAccountList/ACTION$getFilterAccounts
Failing descriptor: {c:AccList}

**************component
<aura:component controller="getAccountList">
    <aura:attribute name="AccList" type="List" />
    <lightning:button label="Get All Filter Accounts" onclick="{! c.getFilterAccountss}" />
    <aura:iteration items="{! v.AccList}" var="Acc" >
        <tr>
            <td>{! Acc.Id}</td>
            <td>{! Acc.Name}</td>
            <td>{! Acc.Phone}</td>
            <td>{! Acc.Type}</td>
        </tr>
    </aura:iteration>
</aura:component>
********************apex class
public class getAccountList {
   
     @AuraEnabled
    public static List<Account> getFilterAccounts(){
        return[select Id,Name,Type,Phone from Account where Type='Prospect'];
    }

}
************************controller
({
    getFilterAccountss : function(component, event, helper) {
        var accRef = component.get("c.getFilterAccounts");
        accRef.setCallback(this,function (response){
           var response = response.getState(); 
            if(response=="SUCCESS"){
                //alert("Success");
                  component.set("v.AccList",response.getReturnValue());
            }else{alert("No Response")}
        });
        $A.enqueueAction(accRef);
    }
   
})

please help me to resolve this issue
Best Answer chosen by sakthidharan Ambayiram
Raj VakatiRaj Vakati
Change your code as below  .. problem in your code is you have used two response variables .. one to the function arg and one to the status so javascript will try to call the getReturnValue method on the result value where there is no getReturnValue method 

 
({
    getFilterAccountss : function(component, event, helper) {
        var accRef = component.get("c.getFilterAccounts");
        accRef.setCallback(this,function (response){
            var result = response.getState(); 
            if(result=="SUCCESS"){
                //alert("Success");
                component.set("v.AccList",response.getReturnValue());
            }else{
                alert("No Response");
            }
        });
        $A.enqueueAction(accRef);
    }
    
})

 

All Answers

Raj VakatiRaj Vakati
Change your code as below  .. problem in your code is you have used two response variables .. one to the function arg and one to the status so javascript will try to call the getReturnValue method on the result value where there is no getReturnValue method 

 
({
    getFilterAccountss : function(component, event, helper) {
        var accRef = component.get("c.getFilterAccounts");
        accRef.setCallback(this,function (response){
            var result = response.getState(); 
            if(result=="SUCCESS"){
                //alert("Success");
                component.set("v.AccList",response.getReturnValue());
            }else{
                alert("No Response");
            }
        });
        $A.enqueueAction(accRef);
    }
    
})

 
This was selected as the best answer
Raj VakatiRaj Vakati
Is its working ?
sakthidharan Ambayiramsakthidharan Ambayiram
ya its working, thanks a lot