• HIMANSHU SINGH 82
  • NEWBIE
  • 0 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies
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

Hi all ,

          I want to know what is the exact difference between salesforce.com and Force.com ,

          Can any one help me to know about that?