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
harsha vardhan vasa 9harsha vardhan vasa 9 

getting error as from server : SecureAction: [object Object]{ key: {"namespace":"c"} }

Hi All,
i have written sample aura component to fetch contacts . but from controller.js not able invoke apex method. getting 
SecureAction: [object Object]{ key: {"namespace":"c"} } error.
below is my code :
component:

<aura:component controller="contactlistcontroller">
    
    <aura:attribute  name="contacts" type="contact[]"/>
    
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    
    <aura:iteration items="{!v.contacts}" var ="con">
        <p> {!con.name} </p> <br></br>
        <p> {!con.lastname} </p>
    </aura:iteration>
</aura:component>


controller.js

 ({
    doInit : function(component, event, helper) {
        var action = component.get("c.findAll");
        
        $A.enqueueAction(action);
        action.setCallback(this,function(response){
            alert(""+response);
            var state= response.getState();
            if(state ==="SUCCESS"){
                var responsestate = response.getReturnValue();
                component.set("v.contacts",responsestate);
            }
            
        });
        
    }
})



apex class:
public class contactlistcontroller {
    
    @AuraEnabled
    public static list<contact> findAll(){
        
        return[select name,lastname from contact limit 50];
    }
    
    @AuraEnabled
    public static list<contact> findByName(string searchkey){
        string name = '%' +searchkey +'%';
        return[select name,lastname from contact where name like :name limit 50];
        
    }
    @AuraEnabled
    public static contact findById(string contactid){
        return[select id,name,lastname from contact where id =:contactid];
    }

}

Regards,
Harsha
Maharajan CMaharajan C
HI Harsha, 

Please do the below changes:

$A.enqueueAction(action); --> use in the bottom.
 
({
    doInit : function(component, event, helper) {
        var action = component.get("c.findAll");
        action.setCallback(this,function(response){
            var state= response.getState();
            if(state ==="SUCCESS"){
                alert(" --> "+ JSON.stringify(response.getReturnValue()));
                component.set("v.contacts", response.getReturnValue());
            }
        });
        $A.enqueueAction(action);
    }
})

In HTML:

Change the Caps...

<p> {!con.name} </p> <br></br>   ==>  <p> {!con.Name} </p> <br></br>
 <p> {!con.lastname} </p>  ==>  <p> {!con.LastName} </p>
 
<aura:component implements="flexipage:availableForAllPageTypes" access="global" controller="contactlistcontroller1">
    <aura:attribute  name="contacts" type="contact[]"/>
    
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    
    <aura:iteration items="{!v.contacts}" var ="con">
        <p> {!con.Name} </p> <br></br>
        <p> {!con.LastName} </p>        
    </aura:iteration>
</aura:component>

Thanks,
Maharajan.C