I am calling an Apex function from helper but it is throwing the below error

This page has an error. You might just need to refresh it. Error in $A.getCallback() [updatemethod is not defined] Callback failed: apex://comApexcontroler/ACTION$updatemethod Failing descriptor: {markup://c:AccComponent}

The below code is just part of the code. In console I am getting pid and aID.

Apex Controller :

    public Static String updatemethod(String pid, String aID){
            String message;

         List<Opportunity> oplist= new List<Opportunity>();
        oplist= [Select Id,Name,lookup__c from Opportunity where id=:pid limit 1];

        for(Opportunity opp: oplist){
            opp.lookup__c = aID;
            message= 'Success';

        update oplist;
        return 'Success';

Component Helper :

 fun1: function(component, event, aID){
       var url= component.get("v.url");  
       var pid= component.get("v.pid");
       var action = component.get('c.updatemethod'); 
         action.setParams({ "pid" : pid,
                                 "aID": aID
        action.setCallback(this, function(response) {
          var state = response.getState();
           console.log('******Valid And State'+'ss'+state); // Here the state is showing as ERROR

              console.log("Entered if" );

                     window.location.href= url;              

  • Also, I'd be remiss if I didn't point out this code is terrible. If you know any one that could give you a code review and explain the whys and hows, I would suggest you do so. There is a lot to be learned; that method could be 1 line. If you don't have anyone, I can put something together and post to gist or something.
    – wellmstein
    Aug 11, 2017 at 16:52
  • @wellmstein Thanks for your response. I am new to Lightning I will learn in the process :) It will be helpful if you can pointout the mistakes
    – Anjali
    Aug 11, 2017 at 16:56
  • here is some basic comments, hope they help. Good luck, keep learning! gist.github.com/maxwellmstein/d096e41838b931d4c7bb4c6793398b9e
    – wellmstein
    Aug 11, 2017 at 19:25

1 Answer 1


inside of your callback you have this


That method is not defined in your javascript. Not sure what you want to happen on success, either define that method on the helper and call helper.updatemethod or remove it. Just as warning be careful not to name your APEX methods the same name as your lightning-controller methods.

You must log in to answer this question.

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