You need to sign in to do that
Don't have an account?
harsha 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
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
Please do the below changes:
$A.enqueueAction(action); --> use in the bottom.
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>
Thanks,
Maharajan.C