+ Start a Discussion
Vigneshwaran LoganathanVigneshwaran Loganathan 

Error in $A.getCallback() [quickcon is not defined]

I am facing "Error in $A.getCallback() [quickcon is not defined]" and not able to find whats the issue, can anyone help? 

Component
<aura:component implements="force:appHostable,force:hassObjectName,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" 
                controller="RatingVsAccount">
   
   <aura:attribute name="cons" type="Contact" />
    <aura:registerEvent name="quickcontact" type="c:QuickContactEvent"></aura:registerEvent>
                   
    
    <aura:attribute name="newContact" type="Contact" default="{'sobjectType': 'Contact',
                                                              'FirstName':'',
                                                              'LastName':'',
                                                              'Email':'',
                                                              'Phone':''
                                                              }"/>
    <div class="slds-col-grid">
         <lightning:input aura:id="fieldId"
                             required="true"
                             label="Last Name"
                             name="filename"
                          	 type="text"
                        	 message-when-value-missing="This field is mandatory"	
                             value="{!v.newContact.LastName}"/>
       
        <lightning:button label="save" onclick="{!c.savecontact}"/>
    </div>
</aura:component>

Controller
({
	savecontact : function(component, event, helper) {
		
       
   
        var action = component.get("c.save");
        
        
            var con = component.get("v.newContact");
            action.setParams({
                con : con,
                Accid : component.get('v.AccountId'),
            });
        
		action.setCallback(this, function(a) {
					   var state = a.getState();
						if (state === "SUCCESS") {
							var name = a.getReturnValue();
						   var CompEvent = component.getEvent('quickcontact');
											   CompEvent.setParams({ quickcon, name});
											   
											   CompEvent.fire();  
							}
						});
		$A.enqueueAction(action)    
        },
	
})

Apex method
@AuraEnabled
    public static Contact save(contact con, string Accid)
    {
        
        con.AccountId = Accid;
        
        insert con;
        system.debug('>>> con' + con);
        return con;
        
    }
Event
<aura:event type="COMPONENT" description="Event template" >
   <aura:attribute name="quickcon" type="Contact"></aura:attribute> 
</aura:event>

Many Thanks for your help
 
Best Answer chosen by Vigneshwaran Loganathan
Khan AnasKhan Anas (Salesforce Developers) 
Hi Vigneshwaran,

Greetings to you!

There is a typo in JS controller on this line: CompEvent.setParams({ quickcon, name});
You need to set the params like below:
CompEvent.setParams({ quickcon : name});

Use below controller:
({
    savecontact : function(component, event, helper) {
        
        
        
        var action = component.get("c.save");
        
        
        var con = component.get("v.newContact");
        action.setParams({
            con : con,
            Accid : component.get('v.AccountId'),
        });
        
        action.setCallback(this, function(a) {
            var state = a.getState();
            if (state === "SUCCESS") {
                var name = a.getReturnValue();
                var CompEvent = component.getEvent('quickcontact');
                CompEvent.setParams({ quickcon : name});
                
                CompEvent.fire();  
            }
        });
        $A.enqueueAction(action)    
    },
    
})

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas

All Answers

Khan AnasKhan Anas (Salesforce Developers) 
Hi Vigneshwaran,

Greetings to you!

There is a typo in JS controller on this line: CompEvent.setParams({ quickcon, name});
You need to set the params like below:
CompEvent.setParams({ quickcon : name});

Use below controller:
({
    savecontact : function(component, event, helper) {
        
        
        
        var action = component.get("c.save");
        
        
        var con = component.get("v.newContact");
        action.setParams({
            con : con,
            Accid : component.get('v.AccountId'),
        });
        
        action.setCallback(this, function(a) {
            var state = a.getState();
            if (state === "SUCCESS") {
                var name = a.getReturnValue();
                var CompEvent = component.getEvent('quickcontact');
                CompEvent.setParams({ quickcon : name});
                
                CompEvent.fire();  
            }
        });
        $A.enqueueAction(action)    
    },
    
})

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
This was selected as the best answer
Vigneshwaran LoganathanVigneshwaran Loganathan
Thanks Khan, I missed it!