0

I have an action that returns a list of Account objects. Account object has a custom object field called Support__c that I want to get the name of the Support__c instead of getting the objectID. So, I am calling getSupport within getAccounts's callback. I am debugging the getAccount function, but it is not called (does not log anything).

Code:

.js

action_get_accounts.setCallback(this, function(data) {
    var returnedObject = data.getReturnValue();
    for (i = 0; i<returnedObject.length; i++) {
        //Prints here
        var action_get_support_name = component.get("c.getSupport");
        action_get_support_name({suportId: cvs['Support__c']});
        action_get_support_name.setCallback(this, function(data) {
            returnedObject[i]['Account__c'] = date.getReturnValue();
        });
        $A.enqueueAction(action_get_account_name);
    }
}
$A.enqueueAction(action_get_accounts); 

.apxc

@AuraEnabled
    public static String getSupportName(Id supportId) {    
        System.debug('function called'); //does not print here
        Support__c support =[Select Name FROM Support__c WHERE id = :supportId];
        return support.Name;
    }

1 Answer 1

0

Your javascript is just wrong:

action_get_support_name is used but not declared

returnedObject.length[i]['Account__c'] is almost certain not to work. returnedObject.length is number, so applying [i] to it will not work.

I suggest you step through in your browser's debugger. Change it to:

action_get_accounts.setCallback(this, function(data) {
    var returnedObject = data.getReturnValue();
    for (i = 0; i<returnedObject.length; i++) {
        //Prints here
        debugger;
...

Then run with developer tools open, and step through until all the JS problems are resolved.

3
  • Sorry, I edit the code to be the correct one now.
    – matchi
    Jan 26, 2018 at 11:17
  • where can I see the debugger? It does not show anything in console or dev console log.
    – matchi
    Jan 26, 2018 at 11:20
  • Did you add the debugger line to your code, like I did in my answer? If you do that, and load the page with developer tools open, your browser should open the debugger automatically when it reaches that line. See developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…
    – Aidan
    Jan 26, 2018 at 11:22

You must log in to answer this question.

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