I am trying to create a lightning component, but I get Unknown controller action 'getContacts' error when trying to load the page. What is the main reason I get that error?

Server-side Controller:

public class MatchedCorporateController {
    public static List<Corporate_Volunteer_Support__c> getContacts(Support__c support) {
       return [Select Account__c From Corporate_Volunteer_Support__c Where Support__c = :support];

Lightning Component:

<aura:component controller="MatchedCorporateController" implements="flexipage:availableForRecordHome,force:hasRecordId" access="global" >

    <aura:attribute name="recordId" type="Id" />
    <aura:attribute name="Opportunity" type="Volunteer_Opportunity__c" />
    <aura:attribute name="support" type="Support__c" default="{!v.Opportunity.Support__c}"/>
    <aura:attribute name="corporateVolunteerSupports" type="Corporate_Volunteer_Support__c" />
    <aura:attribute name="Columns" type="List" />

    <aura:handler name="init" value="{!this}" action="{!c.myAction}" />

    <force:recordData aura:id="accountRecord"

    <lightning:card iconName="standard:record" title="{! 'Matched Corporate Volunteers offering ' + v.support  }">
        <!-- Contact list goes here -->
        <lightning:datatable data="{! v.corporateVolunteerSupports }" columns="{! v.Columns }" hideCheckboxColumn="true"/> 



I follows a module called 'Quick Start: Lightning Components' in Trailhead and tried to adapt it to my code, so there are some things I don't use, such as the recordId.

Client-side Controller:

    myAction : function(component, event, helper) {
        component.set("v.Columns", [
            {label:"Name", fieldName:"Name", type:"text"}//,

    var action = component.get("c.getContacts");
        support: component.get("v.support")

    action.setCallback(this, function(data) {
        component.set("v.corporateVolunteerSupports", data.getReturnValue());

  • is your SOQL searchspec valid? You are passing an entire object into searchspec. Should it just not be id? of support object. Also add a try catch to server method to ensure if there are exceptions it gets caught and you know there is a error – RedDevil Jan 17 '18 at 2:13
  • I don't know why you get this specific error, but I can see one problem - you are sending to the server a Support__c object, but your default value in it's attribute is wrong - default="{!v.Opportunity.Support__c}", instead of this (which will contain an id), you should enter a valid object like that: default="{ 'sobjectType': 'Support__c','Name': 'test'}". maybe that can fix your problem – Itai Shmida Jan 17 '18 at 7:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.