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
Uttpal chandraUttpal chandra 

Error in $A.getCallback() [componnet is not defined] Callback failed: apex://CreateCandidateRecord/ACTION$createRec Failing descriptor: {c:hello}

Hi,
Anyone Solve this.

I am trying to save record using Lightning component but i am getting error "Error in $A.getCallback() [componnet is not defined] Callback failed: apex://CreateCandidateRecord/ACTION$createRec Failing descriptor: {c:hello}"

Below I have mentioned my class.

Hello.cmp
<aura:component controller="CreateCandidateRecord">
 
    <aura:attribute name="Tax" type="Taxes__c" default="{'sobjectType': 'Taxes__c',
                         'Name': '',
                         'Last_Name__c': '', 
                         'SSN__c': ''
                       }"/>
    <aura:attribute name="Id" type="String"/> 
    
    <lightning:input value="{v.Tax.Name}" label="Name" placeholder="Enter name......" />
    <lightning:input value="{v.Tax.Last_Name__c}" label="Last Name" placeholder="Enter Last name......" />
    <lightning:input value="{v.Tax.SSN__c}" label="SSN No" placeholder="Enter SSN No....." />
    <lightning:button variant="brand" label="Save" title="Save" onclick="{!c.doSave}" />
</aura:component>

helloController.js
({
    doSave : function(component,event,helper)  {
    	var action = component.get("c.createRec");    
        action.setParams({'contObj':component.get('v.Tax')});
        action.setCallback(this,function(data){
            componnet.set('v.Id',data.getReturnValue())
        });
        $A.enqueueAction(action);
    }
    
})

harness.app
<aura:application extends="force:slds" >
    <c:hello/>
</aura:application>

CreateCandidateRecord.apxc
public class CreateCandidateRecord {

    
@AuraEnabled
     public static string createRec(Taxes__c contObj){
        
        System.debug('Taxes::' +contObj.Name);
         insert contObj;
         return contObj.Id;
        
    }    
    
}

Thanks in advance
Uttpal
Best Answer chosen by Uttpal chandra
Khan AnasKhan Anas (Salesforce Developers) 
Hi Uttpal,

Greetings to you!

You are getting this because of a typo inthe JS controller. You are using componnet.set('v.Id',data.getReturnValue()) instaed of component.set('v.Id', data.getReturnValue());
Semicolon is also missing.
 
({
    doSave : function(component,event,helper)  {
    	var action = component.get("c.createRec");    
        action.setParams({'contObj':component.get('v.Tax')});
        action.setCallback(this,function(data){
            component.set('v.Id',data.getReturnValue());
        });
        $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 Uttpal,

Greetings to you!

You are getting this because of a typo inthe JS controller. You are using componnet.set('v.Id',data.getReturnValue()) instaed of component.set('v.Id', data.getReturnValue());
Semicolon is also missing.
 
({
    doSave : function(component,event,helper)  {
    	var action = component.get("c.createRec");    
        action.setParams({'contObj':component.get('v.Tax')});
        action.setCallback(this,function(data){
            component.set('v.Id',data.getReturnValue());
        });
        $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
Uttpal chandraUttpal chandra
Hi Anas,

Thanks it worked my typo error.

Thanks and Regards,
Uttpal Chandra
Uttpal chandraUttpal chandra
Hi Anas,

I want to clear my text fields after inserting the data.Can you help me on this..??
Khan AnasKhan Anas (Salesforce Developers) 
Try this:
 
({
    doSave : function(component,event,helper)  {
    	var action = component.get("c.createRec");    
        action.setParams({'contObj':component.get('v.Tax')});
        action.setCallback(this,function(data){
            component.set('v.Id',data.getReturnValue());
            component.set('v.Tax','');
        });
        $A.enqueueAction(action);
    }
    
})

Regards,
Khan Anas
Uttpal chandraUttpal chandra
Hi Anas,
I had also solved it by myself but that has a more line of code.Thanks for this oneliner.

Regards,
Uttpal