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
Aratz GuerraAratz Guerra 

Uncaught Error in $A.getCallback() [Cannot read property 'SBQQ__EndDate__c' of null]

Hi, this is my Lightning component code:
 
<aura:component implements="force:lightningQuickActionWithoutHeader,force:hasRecordId" access="global">
    
    <!-- Define Attribute-->
    <aura:attribute name="newQuote" type="Object"/>
    <aura:attribute name="simpleNewQuote" type="Object" default="{'sobjectType':'SBQQ__Quote__c', 'SBQQ__EndDate__c':2018-01-01}"/>
    <aura:attribute name="newQuoteError" type="String"/>    
    
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>

    <force:recordData aura:id="QuoteRecordCreator" 
                      layoutType="FULL"
                      targetRecord="{!v.newQuote}"
                      targetFields="{!v.simpleNewQuote}"
                      targetError="{!v.newQuoteError}" />
                      
    <div class="slds-modal__header">
        <h2 class="slds-text-heading--medium">New Quote</h2>
    </div>

    <!-- Display the new quote form -->
    <div class="slds-form_stacked">
        
        <lightning:input aura:id="QuoteField" type="date" name="Notes" label="Offer end date"
                         value="{!v.simpleNewQuote.SBQQ__EndDate__c}"/>
        <lightning:textarea aura:id="QuoteField" name="Notes" label="Additional notes"
                         value="{!v.simpleNewQuote.SBQQ__Notes__c}"/>

        
        <lightning:button label="Create Quote" onclick="{!c.handleSaveQuote}"
                   variant="brand" class="slds-m-top_medium"/>
   </div>

</aura:component>

But when I select a Date, the following error appears:

Uncaught Error in $A.getCallback() [Cannot read property 'SBQQ__EndDate__c' of null]
throws at https://hum.lightning.force.com/auraFW/javascript/1bO4dJePbDnoI-_VdhdsEQ/aura_proddebug.js:31064:9. Caused by: Error in $A.getCallback() [Cannot read property 'SBQQ__EndDate__c' of null]
AttributeSet.set()@https://hum.lightning.force.com/auraFW/javascript/1bO4dJePbDnoI-_VdhdsEQ/aura_proddebug.js:22401:12
componentConstructor.Component.set()@https://hum.lightning.force.com/auraFW/javascript/1bO4dJePbDnoI-_VdhdsEQ/aura_proddebug.js:16854:37
PropertyReferenceValue.set()@https://hum.lightning.force.com/auraFW/javascript/1bO4dJePbDnoI-_VdhdsEQ/aura_proddebug.js:15155:41
AttributeSet.set()@https://hum.lightning.force.com/auraFW/javascript/1bO4dJePbDnoI-_VdhdsEQ/aura_proddebug.js:22402:17
componentConstructor.Component.set()@https://hum.lightning.force.com/auraFW/javascript/1bO4dJePbDnoI-_VdhdsEQ/aura_proddebug.js:16854:37
Object.onNodeValueChange()@https://hum.lightning.force.com/components/lightning/input.js:319:27
Object.eval [as input]()@https://hum.lightning.force.com/libraries/lightning/domLibrary/dom.js:218:33
runSyntheticEvent()@https://hum.lightning.force.com/libraries/lightning/domLibrary/dom.js:128:27
HTMLInputElement.eventListener()@https://hum.lightning.force.com/libraries/lightning/domLibrary/dom.js:131:24


Can anyone tell me how to solve it please?
Best Answer chosen by Aratz Guerra
Narender Singh(Nads)Narender Singh(Nads)
Hi,

Try this code in your JS controller:
({
    doInit: function(component, event, helper) {
        // Prepare a new record from template
        component.find("QuoteRecordCreator").getNewRecord(
            "SBQQ_Quote__c", // sObject type (objectApiName)
            null,      // recordTypeId
            false,     // skip cache?
            $A.getCallback(function() {
                var rec = component.get("v.newQuote");
                var error = component.get("v.newQuoteError");
                if(error || (rec === null)) {
                    console.log("Error initializing record template: " + error);
                    return;
                }
                console.log("Record template initialized: " + rec.sobjectType);
            })
        );
    },

    handleSaveQuote: function(component, event, helper) {
            component.set("v.simpleNewQuote.SBQQ_Opportunity2__c", component.get("v.recordId"));
            component.set("v.simpleNewQuote.SBQQ_LineItemsGrouped__c", true);
            component.set("v.simpleNewQuote.SBQQ_Primary__c", true);
            component.find("QuoteRecordCreator").saveRecord(function(saveResult) {
                if (saveResult.state === "SUCCESS" || saveResult.state === "DRAFT") {
                    // record is saved successfully
                    var resultsToast = $A.get("e.force:showToast");
                    resultsToast.setParams({
                        "type": 'success',    
                        "title": "Saved",
                        "message": "The new quote has been created."
                    });
                    resultsToast.fire();
                    helper.navigateTo(component, saveResult.recordId);


                } else if (saveResult.state === "INCOMPLETE") {
                    // handle the incomplete state
                    console.log("User is offline, device doesn't support drafts.");
                } else if (saveResult.state === "ERROR") {
                    // handle the error state
                    
                    var errors = response.getError();
                    var resultsToast = $A.get("e.force:showToast");
                    resultsToast.setParams({
                        "type":"error",
                        "title": "Error!",
                        "message": errors
                        //"message": "The new quote has an error." + saveResult.state + ", error: " + JSON.stringify(saveResult.error)
                    });
                    resultsToast.fire();
                    
                    helper.navigateTo(component, saveResult.recordId);
                    console.log('Problem saving contact, error: ' + JSON.stringify(saveResult.error));
                } else {
                    console.log('Unknown problem, state: ' + saveResult.state + ', error: ' + JSON.stringify(saveResult.error));
                }
            });
    }
})

Let me know if it helps.
Thanks!

All Answers

Narender Singh(Nads)Narender Singh(Nads)
Hi,
Can you please share the JS controller code as well?
Narender Singh(Nads)Narender Singh(Nads)
Hi,

Try this code in your JS controller:
({
    doInit: function(component, event, helper) {
        // Prepare a new record from template
        component.find("QuoteRecordCreator").getNewRecord(
            "SBQQ_Quote__c", // sObject type (objectApiName)
            null,      // recordTypeId
            false,     // skip cache?
            $A.getCallback(function() {
                var rec = component.get("v.newQuote");
                var error = component.get("v.newQuoteError");
                if(error || (rec === null)) {
                    console.log("Error initializing record template: " + error);
                    return;
                }
                console.log("Record template initialized: " + rec.sobjectType);
            })
        );
    },

    handleSaveQuote: function(component, event, helper) {
            component.set("v.simpleNewQuote.SBQQ_Opportunity2__c", component.get("v.recordId"));
            component.set("v.simpleNewQuote.SBQQ_LineItemsGrouped__c", true);
            component.set("v.simpleNewQuote.SBQQ_Primary__c", true);
            component.find("QuoteRecordCreator").saveRecord(function(saveResult) {
                if (saveResult.state === "SUCCESS" || saveResult.state === "DRAFT") {
                    // record is saved successfully
                    var resultsToast = $A.get("e.force:showToast");
                    resultsToast.setParams({
                        "type": 'success',    
                        "title": "Saved",
                        "message": "The new quote has been created."
                    });
                    resultsToast.fire();
                    helper.navigateTo(component, saveResult.recordId);


                } else if (saveResult.state === "INCOMPLETE") {
                    // handle the incomplete state
                    console.log("User is offline, device doesn't support drafts.");
                } else if (saveResult.state === "ERROR") {
                    // handle the error state
                    
                    var errors = response.getError();
                    var resultsToast = $A.get("e.force:showToast");
                    resultsToast.setParams({
                        "type":"error",
                        "title": "Error!",
                        "message": errors
                        //"message": "The new quote has an error." + saveResult.state + ", error: " + JSON.stringify(saveResult.error)
                    });
                    resultsToast.fire();
                    
                    helper.navigateTo(component, saveResult.recordId);
                    console.log('Problem saving contact, error: ' + JSON.stringify(saveResult.error));
                } else {
                    console.log('Unknown problem, state: ' + saveResult.state + ', error: ' + JSON.stringify(saveResult.error));
                }
            });
    }
})

Let me know if it helps.
Thanks!
This was selected as the best answer
Narender Singh(Nads)Narender Singh(Nads)
Hi, 
Also in your component, change line 5 i.e: <aura:attribute name="simpleNewQuote" type="Object" default="{'sobjectType':'SBQQ__Quote__c', 'SBQQ__EndDate__c':2018-01-01}"/>

with 
<aura:attribute name="simpleNewQuote" type="Object" default="{'sobjectType':'SBQQ_Quote__c', 'SBQQ_EndDate__c':2018-01-01}"/>
 
Aratz GuerraAratz Guerra
Thank you Nads, now I can continue with the rest of the work!