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
Niraj Singh 28Niraj 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;
    }
}
Best Answer chosen by Niraj Singh 28
Raj VakatiRaj Vakati
My bad .. pasted wrong code here is the correct code .. javascript is case sensitive 
 
public class ContactOperation {
    @AuraEnabled
    public static List<Contact> getAllContact(){
        return  [Select FirstName,LastName, Phone, Email, Title,Account.Name from Contact];
    }
}
 
<aura:component implements="force:appHostable" controller="ContactOperation">
    <aura:attribute name="cnts" type="Contact[]"/>
    
    <aura:handler name="init" action="{!c.doInit}" value="{!this}"/>   
    {!v.cnts}
    <aura:iteration  items="{!v.cnts}" var="con" >
        {!con.LastName}
    </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();
            console.log(response.getReturnValue());
            if (state == "SUCCESS") {
                component.set("v.cnts", response.getReturnValue());
            }
            else {
                console.log("Failed with state: " + state);
            }
        });
        // Send action off to be executed
        $A.enqueueAction(action);
    }
    
})

 

All Answers

Syed Insha Jawaid 2Syed Insha Jawaid 2
Hi Niraj 

Change the annotation from @RemoteAction to @AuraEnabled.

Cheers!!!
Raj VakatiRaj Vakati
Change your controller as below
 
public class ContactOperation {
     @AuraEnabled
    public static List<contact> getAllContact(){
       return  [Select firstName,LastName, Phone, Email, Title,Account.Name from contact];
    }
}

 
Niraj Singh 28Niraj Singh 28
After changing annotation gettting same error
 
Raj VakatiRaj Vakati
This code is wokring 
 
<aura:component implements="force:appHostable" controller="ContactOperation">
    
    <aura:handler name="init" action="{!c.doInit}" value="{!this}"/>   
    <aura:attribute name="cnts" type="Contact[]"/>
    <aura:iteration  items="{!v.cnts}" var="con" >
        {!con.FirstName}
    </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();
            console.log(response.getReturnValue());
            if (state == "SUCCESS") {
                component.set("v.cnts", response.getReturnValue());
            }
            else {
                console.log("Failed with state: " + state);
            }
        });
        // Send action off to be executed
        $A.enqueueAction(action);
    }
    
})
 
public class ContactOperation {
    @AuraEnabled
    public static List<Contact> getAllContact(){
        return  [Select firstName,LastName, Phone, Email, Title,Account.Name from Contact];
    }
}

 
Niraj Singh 28Niraj Singh 28
@Raj Vakati

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>
Raj VakatiRaj Vakati
My bad .. pasted wrong code here is the correct code .. javascript is case sensitive 
 
public class ContactOperation {
    @AuraEnabled
    public static List<Contact> getAllContact(){
        return  [Select FirstName,LastName, Phone, Email, Title,Account.Name from Contact];
    }
}
 
<aura:component implements="force:appHostable" controller="ContactOperation">
    <aura:attribute name="cnts" type="Contact[]"/>
    
    <aura:handler name="init" action="{!c.doInit}" value="{!this}"/>   
    {!v.cnts}
    <aura:iteration  items="{!v.cnts}" var="con" >
        {!con.LastName}
    </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();
            console.log(response.getReturnValue());
            if (state == "SUCCESS") {
                component.set("v.cnts", response.getReturnValue());
            }
            else {
                console.log("Failed with state: " + state);
            }
        });
        // Send action off to be executed
        $A.enqueueAction(action);
    }
    
})

 
This was selected as the best answer
Syed Insha Jawaid 2Syed Insha Jawaid 2
Hi Niraj

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!!!!