0

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) {
    console.log('v.recordId----------->'+cmp.get("v.ClientId"));
    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") {
    }
    }));
    $A.enqueueAction(action);
}



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

     return acr;
 }

Thanks!

  • did you run the query separately in developer console with correct accountId? are you getting any result? – Santanu Boral May 1 '18 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 '18 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. – Pranay Jaiswal May 1 '18 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 – consultantsfdc May 1 '18 at 20:35
  • 3
    Does this account also belong to you? Please do not create or maintain duplicate accounts. – Adrian Larson May 1 '18 at 21:30
0

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');

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.