I am trying to fetch AccountContactRelation recordsrelated to specific accountId from Lightning component via server side call. I am passing the AccountId as a param to the apex controller. But unfortunately the query returns null. Any help would be appreciated. Here is the code of the apex controller class:

doInit : function(cmp, event, helper) {
    var action = cmp.get('c.getrecs);
    action.setParams({"AccountId": cmp.get("v.ClientId")});
    action.setCallback(this, $A.getCallback(function (response) {
    var state = response.getState();
    if (state === "SUCCESS") {
    cmp.set('v.acrrecords', response.getReturnValue()); 
    else if (state === "ERROR") {

   public static list<AccountContactRelation> getrecs(String AccountId){       
    list<AccountContactRelation> acr = [select id,AccountId from AccountContactRelation where AccountId  =:AccountId  ];

     return acr;


  • did you run the query separately in developer console with correct accountId? are you getting any result? May 1, 2018 at 20:26
  • Does the running user have permission to view the records involved? Is the class running with sharing or without sharing?
    – David Reed
    May 1, 2018 at 20:26
  • Can you check the variable name? AccountId in Apex should be same as what you are using in JS controller. You can try running it in workbench if that helps and there is a valid account-contact relationship. May 1, 2018 at 20:28
  • Hi Guys, Yes I ran the query in developer console with hardcoded Id and it returns records. Yes have permissions to view records and the variable name is also exactly matching with the JS controller in lightning component May 1, 2018 at 20:35
  • 3
    Does this account also belong to you? Please do not create or maintain duplicate accounts.
    – Adrian Larson
    May 1, 2018 at 21:30

1 Answer 1


I guess you missed the single quote. Please see your code;

var action = cmp.get('c.getrecs); 

replaced with

var action = cmp.get('c.getrecs');

You must log in to answer this question.

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