1

I'm trying to fetch the list of opportunities related to the account(called as Student in my case) selected(from dropdown list).

I have 2 buttons with different aura:ids what I want is, when I click on the button one I wish to call apex method one(getOpportunities) and save the response to aura:attribute one(lstOpportunities) similarly when I click on button two I wish to call apex method two(getOpportunities1) and save the response in aura:attribute two(lstOpportunities1). In the code below, it's calling the helper method recursively infinite times.

However, if I uncomment the if else statements then it's not calling the setCallback code block. My helper method is

helperGetOpportunities : function(component,event){
    var selectedStudentId;
    var getLstOpportunities;
    //if(event.getSource().getLocalId() === 'showstudentsfromsearchbypicklist'){ //aura:Id of student's select option
        console.log('1111');
        selectedStudentId = component.get('v.selectedStudentId');
        getLstOpportunities = component.get('c.getOpportunities');
    //}
    //else{
      //  selectedStudentId = component.get('v.selectedStudentId1');
      //  getLstOpportunities = component.get('c.getOpportunities1');
    //}
    console.log('Id is : '+selectedStudentId);
    getLstOpportunities.setParams({
        studentId : selectedStudentId
    });        
    getLstOpportunities.setCallback(this , function(response){
        var state = response.getState();
        console.log('Here i am 1');
        if(state === 'SUCCESS'){
            console.log('Here i am 2');
            //if(event.getSource().getLocalId() === 'showstudentsfromsearchbypicklist'){ //aura:Id of student's select option
                console.log('response is : '+response.getReturnValue());
                component.set("v.lstOpportunities",response.getReturnValue());
           // }
           // else{
                //component.set("v.lstOpportunities1",response.getReturnValue());
            //}

        }
    });
    $A.enqueueAction(getLstOpportunities);
}

The apex methods getOpportunities and getOpportunities1 are only returning the list of opportunities related to given student id. Can anyone help me in finding the problem with this code?

1 Answer 1

3

When your helper is getting called recursively, it means you have a method name conflict between the client and server, which, in this case, appears to be getOpportunities. You should probably have a warning on the browser's console log to this effect. Always make sure that there are not client-side and controller-side AuraEnabled methods with the same name.

0

You must log in to answer this question.

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