You need to sign in to do that
Don't have an account?
Niraj Singh 28
Unable to find action 'getAllContact' on the controller of c:TestComponent
Please have a look below, what i am going to do wrong.
<aura:component implements="force:appHostable" controller="ContactOperation">
<aura:attribute name="contacts" type="contact[]"/>
<aura:handler name="init" action="{!c.doInit}" value="{!this}"/>
<aura:Iteration var="con" Items="{!v.contacts}">
<lightning:outputField value="{!con.FirstName}"></lightning:outputField>
</aura:Iteration>
</aura:component>
({
// Load expenses from Salesforce
doInit: function(component, event, helper) {
// Create the action
var action = component.get("c.getAllContact");
// Add callback behavior for when response is received
action.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS") {
component.set("v.contacts", response.getReturnValue());
}
else {
console.log("Failed with state: " + state);
}
});
// Send action off to be executed
$A.enqueueAction(action);
}
})
public class ContactOperation {
@RemoteAction
public static List<contact> getAllContact(){
List<contact> lstContact=[Select firstName,LastName, Phone, Email, Title,Account.Name from contact];
return lstcontact;
}
}
<aura:component implements="force:appHostable" controller="ContactOperation">
<aura:attribute name="contacts" type="contact[]"/>
<aura:handler name="init" action="{!c.doInit}" value="{!this}"/>
<aura:Iteration var="con" Items="{!v.contacts}">
<lightning:outputField value="{!con.FirstName}"></lightning:outputField>
</aura:Iteration>
</aura:component>
({
// Load expenses from Salesforce
doInit: function(component, event, helper) {
// Create the action
var action = component.get("c.getAllContact");
// Add callback behavior for when response is received
action.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS") {
component.set("v.contacts", response.getReturnValue());
}
else {
console.log("Failed with state: " + state);
}
});
// Send action off to be executed
$A.enqueueAction(action);
}
})
public class ContactOperation {
@RemoteAction
public static List<contact> getAllContact(){
List<contact> lstContact=[Select firstName,LastName, Phone, Email, Title,Account.Name from contact];
return lstcontact;
}
}
All Answers
Change the annotation from @RemoteAction to @AuraEnabled.
Cheers!!!
I am not getting Error but not getting output also Please have a look for complete code
<aura:component implements="force:appHostable" controller="ContactsController">
<aura:handler name="init" action="{!c.doInit}" value="{!this}"/>
<aura:attribute name="cnts" type="contact[]"/>
<aura:Iteration var="con" Items="{!v.cnts}">
{!con.firstName}
</aura:Iteration>
</aura:component>
({
// Load expenses from Salesforce
doInit: function(component, event, helper) {
alert('hi');
// Create the action
var action = component.get("c.getAllContact");
// Add callback behavior for when response is received
action.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS") {
component.set("v.cnts", response.getReturnValue());
console.log(response.getReturnValue());
}
else {
console.log("Failed with state: " + state);
}
});
// Send action off to be executed
$A.enqueueAction(action);
}
})
public class ContactsController {
@AuraEnabled
public static List<Contact> GetAllContactsByName(String searchText) {
String searchString = '%' + searchText + '%';
List<Contact> contactList = [SELECT FirstName, LastName, Phone, Email, Title, Account.Name FROM Contact where FirstName like :searchString];
return contactList;
}
@AuraEnabled
public static List<contact> getAllContact(){
List<contact> lstContact=[Select firstName,LastName, Phone, Email, Title,Account.Name from contact];
return lstcontact;
}
}
<aura:application extends="force:slds">
<c:TestComponent />
</aura:application>
Replace your markup with following :
<aura:component implements="force:appHostable" controller="ContactsController">
<aura:handler name="init" action="{!c.doInit}" value="{!this}"/>
<aura:attribute name="cnts" type="Contact[]"/>
<aura:iteration var="con" items="{!v.cnts}">
{!con.FirstName}
</aura:iteration>
</aura:component>
You need to keep in mind that Aura Framework is case sensitive.
Cheers!!!!