ReferenceError: Error in $A.getCallback() [cmp is not defined] Callback failed: serviceComponent://ui.force.components.controllers.recordGlobalValueProvider.RecordGvpController/ACTION$saveRecord

I am creating a clone lightning component that lets the user see a view of an existing records fields, change what they will, then save that new record. After the clicking the save button I got the above error. I have no idea what it is saying.

handelSaveRecord : function(component, event, helper) {
    component.find("ClonedExamCreator").saveRecord($A.getCallback(function(saveResult) {
        if (saveResult.state === "SUCCESS" || saveResult.state === "DRAFT") {
            console.log("Save completed successfully.");
            cmp.set("v.recordSaveError", '');
        } else if (saveResult.state === "INCOMPLETE") {
            console.log("User is offline, device doesn't support drafts.");
            cmp.set("v.recordSaveError", '');
        } else if (saveResult.state === "ERROR") {
           var errMsg = "";
            // console.log('Problem saving record, error: ' + JSON.stringify(saveResult.error));
            // saveResult.error is an array of errors,
            // so collect all errors into one message
            for(var i = 0; i < saveResult.error.length; i++) {
                errMsg += saveResult.error[i].message + "\n";
            cmp.set("v.recordSaveError", errMsg);
        } else {
            console.log('Unknown problem, state: ' + saveResult.state + ', error: ' + JSON.stringify(saveResult.error));
            cmp.set("v.recordSaveError", "");

---------------- Lightning Page---------------------------

<aura:component implements="force:lightningQuickAction,force:hasRecordId,flexipage:availableForRecordHome">

<!--<aura:handler name="init" value="{!this}" action="{!c.doInit}"/> -->

<aura:attribute name="clonedExam" type="Object"/>
<aura:attribute name="clonedExamRecord" type="Object"/>
<aura:attribute name="recordSaveError" type="String"/>

<force:recordData aura:id="ClonedExamCreator"
    mode="EDIT" />  

<!-- Display an editing form -->
<div class="Record Details">
    <lightning:card iconName="action:edit" title="Edit Account">
        <div class="slds-p-horizontal--small">
            <lightning:input label="Name" value="{!v.clonedExamRecord.Name}"/>
            <lightning:input label="Number of Minutes" value="{!v.clonedExamRecord.Number_of_Minutes__c}"/>
            <lightning:input label="Graded" type="checkbox" value="{!v.clonedExamRecord.Graded__c}"/>
            <lightning:input label="Show One Question at a Time" type="checkbox" value="{!v.clonedExamRecord.Show_One_Question_at_a_Time__c}"/>
            <lightning:input label="Show Score Upon Completion" type="checkbox" value="{!v.clonedExamRecord.Show_Score_Upon_Completion__c}"/>
            <lightning:input label="Randomize Question Order" type="checkbox" value="{!v.clonedExamRecord.Randomize_Question_Order__c}"/>
            <lightning:select label="Status" value="{!v.clonedExamRecord.Status__c}">
                <option value="Created">Created</option>
                <option value="Sent">Sent</option>
                <option value="Ungraded">Ungraded</option>
                <option value="Graded">Graded</option>
                <option value="Cancelled">Cancelled</option>
            <lightning:button variant="brand" label="Clone" iconName="action:new_campaign" onclick="{!c.handelSaveRecord}" />

<!-- Display Lightning Data Service errors, if any -->
<aura:if isTrue="{!not(empty(v.recordError))}">
    <div class="recordError">

  • this is a common mistake, when you declare your function "function(component, event, helper)", you need to use the same parameter names. either pass cmp as a parameter or change all your cmp's to component
    – glls
    Commented Dec 6, 2017 at 17:05
  • @glls Can you post that as an as an answer. Commented Dec 6, 2017 at 19:00

1 Answer 1


This is a common mistake, when you declare your function

function(component, event, helper)

you need to use the same parameter names.

We can see in your code that you are using cmp when attemtping to set an attribute value


either pass cmp as a parameter or change all your cmp's to component.


function(cmp, event, helper) { 

You must log in to answer this question.

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