This is my code but I have the Error enter image description here // DynamicRelatedContactListController.apxc

public with sharing class DynamicRelatedContactListController {
    public static List<Contact> getRelatedContacts(Id accountId) {
        List<Contact> relatedContacts = [
            SELECT Id, Name, Email
            FROM Contact
            WHERE Id IN (
                SELECT ContactId 
                FROM AccountContactRelation 
                WHERE AccountId = :accountId AND IsActive = true

        return relatedContacts;
<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId">
    <aura:attribute name="contacts" type="Contact[]"/>
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>

    <aura:iteration items="{!v.contacts}" var="contact">
        <p>Name: {!contact.Name}</p>
        <p>Email: {!contact.Email}</p>

// DynamicRelatedContactListController.js

    doInit: function(component) {
        var accountId = component.get("v.recordId");
        var action = component.get("c.getRelatedContacts");

            "accountId": accountId

        action.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
                component.set("v.contacts", response.getReturnValue());


1 Answer 1


Controller not added on Component. Apex Controller(Server-side controller need to be added on aura:component tag using controller attribute.

<aura:component controller="DynamicRelatedContactListController" implements="flexipage:availableForRecordHome,force:hasRecordId" >

Ref : https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/controllers_server_actions_call.htm

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .