function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sylvie Serplet 18Sylvie Serplet 18 

Getting “Uncaught Error in $A.getCallback() [Cannot read property 'setParams' of undefined].Callback failed:apex...” with aura component

Hi,
I had a javascript button that performed some validation and update via APEX in classic and when transitioning to Lightning I create a Lightning quick action (aura component) to replace it. A button opens the action on the Opportunity detail page in a Lightning console. The component opens fine but when trying to Confirm I got an error message "Uncaught Error in $A.getCallback() [Cannot read property 'setParams' of undefined].Callback failed:apex...".
Aura component:
<aura:component implements="flexipage:availableForAllPageTypes,force:lightningQuickActionWithoutHeader,force:hasRecordId" access="global" controller="ConvertAPEX">             

    <aura:attribute name="recordId" type="String" /> 
    <aura:attribute name="opportunity" type="Opportunity"  /> 

    <div class="slds-hide">
    <lightning:recordEditForm aura:id="editform"
                                  recordId="{!v.recordId}"
                                  objectApiName="Opportunity">        
           <lightning:outputField fieldName="Account_Status__c" aura:id="status"/> 
           <lightning:outputField fieldName="IsClosed_text__c" aura:id="closed"/>  
    </lightning:recordEditForm>    
    </div>

    <div class="slds-modal__header">             
       <h2 class="slds-text-heading_medium slds-hyphenate">Convert</h2>        
    </div>

    <div class="slds-modal__content slds-p-around_medium" id="modal-content-id-1">
         <p>You are about to convert this record.</p>
            <br/>
         <p>Are you sure you want to continue?</p>      
    </div>

    <div class="slds-modal__footer">
        <lightning:button class="slds-button_brand" onclick="{!c.convertRegistration}" label="Confirm" />
        <lightning:button class="slds-button_neutral" onclick="{!c.cancel}" label="Cancel"/>
    </div>

Javascript Controller:
({
    convertRegistration : function(component) {        

        var opp = component.get("v.opportunity");     

        var action = component.get("c.ConvertRegistrationData");
        action.setParams({             
            OppId: component.get("v.recordId")
            });        

        action.setCallback(this, 
           function(response) {           

            var state = response.getState();  
            if (state === "SUCCESS"){  

            component.set("v.opportunity", response.getReturnValue());            

            var accStatus = component.find("status").get("v.value");
            var isClosed = component.find("closed").get("v.value");    

                if (isClosed === "Yes") {
                $A.get("e.force:closeQuickAction").fire();               
                 var toastEvent = $A.get("e.force:showToast");

                toastEvent.setParams({
                    "title": "WARNING!",
                    "type": "warning",   
                    "message": "Can only convert for OPEN opportunities."
                });

                toastEvent.fire();      
                $A.get('e.force:refreshView').fire();

                    }else if(accStatus !== "Unregistered" || accStatus !== "Registered"){
                $A.get("e.force:closeQuickAction").fire();

                toastEvent.setParams({
                    "title": "WARNING!",
                    "type": "warning",   
                    "message": "Can only convert for Unregistered, Registered accounts."
                });

                toastEvent.fire();      
                $A.get('e.force:refreshView').fire();

                }else{  
                   $A.get("e.force:closeQuickAction").fire();

                     toastEvent.setParams({
                    "title" : "Success",
                    "message" : "Merchant converted.",
                    "type" : "success"
                });

                toastEvent.fire(); 
                $A.get('e.force:refreshView').fire();

                }
            }
                else if (response.state === "ERROR") {                 

                var errors = response.getError();                
                $A.get("e.force:closeQuickAction").fire();

                toastEvent.setParams({
                    "title": "Error!",
                    "type": "error",   
                    "message": errors[0].message
                });

                toastEvent.fire();      
                $A.get('e.force:refreshView').fire();
            }    

        });

        $A.enqueueAction(action);
    },   

    cancel : function(){
        $A.get("e.force:closeQuickAction").fire();
        $A.get('e.force:refreshView').fire();
    }    

})

APEX Controller:
global class ConvertAPEX {

   @AuraEnabled
   Webservice static Boolean ConvertRegistrationData(Id OppId)
    {
        boolean retVal = false;

        Savepoint sp = Database.setSavepoint();

        try {

            rego_Branch_Settings__c rbs = rego_Branch_Settings__c.getOrgDefaults();


            Opportunity opp = [select Id
                                        ,AccountId
                                        ,Name
                                        ,Rego__c
                                        ,IsClosed_text__c
                                        ,Account_Status__c 
                                        from Opportunity where Id=: OppId];

            Account acc = [select Id                
                                    ,AccountStatus__c
                                    from Account where Id =: opp.AccountId];

            Rego__c r = getRego(acc.Id);

            boolean registrationCreated = SetFacilitatorRegistration(acc, r, opp);

            r.Provisioning_Supporting_Docs_Required__c = '';                

                //a serie of if statements              

                    {
                        update acc;
                        update opp;
                        update r;

                        retVal = true;
                    }
                    else {
                        throw Exception('Product failed to add.');
                    }   
                }
                else
                {
                    throw Exception('No need to convert.');
                }
            }
        }
        catch (Exception ex)
        {
            Error.SendErrorEmail(ex, 'Unable to Convert Registration');
            retVal = false;
            Database.rollback( sp );
        }

        return retVal;
    }

Thank you in advance for your help.
Sylvie
Danish HodaDanish Hoda
Hi Sylvie,
Please check if below points to resolve this:
1.) If you are using this component inside a Lightning:Application, as toast message isn't supported in Lightning:Application.
2.) Add event parameter inside the JS function like:
 convertRegistration : function(component, event)
HIMANSHU SINGH 82HIMANSHU SINGH 82
@Danish hoda its worked for me. May i know how u got this information?
Danish HodaDanish Hoda
Hi Himanshu,
Thanks for letting me know!
The JS controller method has 3 parameters - component, event, helper
So, if you are working on an event (Toast is a platformEvent) you need to include event as the function parameter, if you are working on helper JS method, you need to include helper as the function parameter